Usage
Spoiler
Internal Navigation works a little differently than most other APIs. Rather than using lots of different functions, you just call one function, inav.createInternalNav() to create a navigation object, then call functions from that object.
For example, to create a navigation object called "myNav", you would use:
After creating that object, all other functions are called by using "myNav" (or whatever you called your object earlier), then a period, then the function name. For example, to call the "forward()" function, you would use:
To use this API, you replace all of your turtle movement functions (like turtle.forward and turtle.back) with functions called just like the one above.
Here is a list of all of the available functions. They are written for the navigation object called "myNav".
Internal Navigation works a little differently than most other APIs. Rather than using lots of different functions, you just call one function, inav.createInternalNav() to create a navigation object, then call functions from that object.
For example, to create a navigation object called "myNav", you would use:
myNav = inav.createInternalNav()
After creating that object, all other functions are called by using "myNav" (or whatever you called your object earlier), then a period, then the function name. For example, to call the "forward()" function, you would use:
myNav.forward()
To use this API, you replace all of your turtle movement functions (like turtle.forward and turtle.back) with functions called just like the one above.
Here is a list of all of the available functions. They are written for the navigation object called "myNav".
myNav.forward() - Replaces turtle.forward() - Returns true if the movement succeeds, false if the movement fails myNav.back() - Replaces turtle.back() - Returns true if the movement succeeds, false if the movement fails myNav.up() - Replaces turtle.up() - Returns true if the movement succeeds, false if the movement fails myNav.down() - Replaces turtle.down() - Returns true if the movement succeeds, false if the movement fails myNav.turnLeft() - Replaces turtle.turnLeft() - Returns true if the movement succeeds, false if the movement fails myNav.turnRight() - Replaces turtle.turnRight() - Returns true if the movement succeeds, false if the movement fails myNav.calibrate(x,y,z,direction) - Sets the current position of the turtle - Defaults to 0 myNav.getPos() - Returns a table containing the current position - "x", "y", and "z" are the coordinates, "dir" is the current direction
Download
http://pastebin.com/3KHq3K2R
Code
Spoiler
function createInternalNav() intab = {} intab.xpos = 0 intab.ypos = 0 intab.zpos = 0 intab.dir = 0 function intab.forward() local moveworked = turtle.forward() if moveworked == true then if intab.dir%4 == 0 then intab.xpos = intab.xpos+1 elseif intab.dir%4 == 1 then intab.zpos = intab.zpos+1 elseif intab.dir%4 == 2 then intab.xpos = intab.xpos-1 elseif intab.dir%4 == 3 then intab.zpos = intab.zpos-1 else print("Massive Error in intab.forward()") end end return moveworked end function intab.back() local moveworked = turtle.back() if moveworked == true then if intab.dir%4 == 0 then intab.xpos = intab.xpos - 1 elseif intab.dir%4 == 1 then intab.zpos = intab.zpos - 1 elseif intab.dir%4 == 2 then intab.xpos = intab.xpos + 1 elseif intab.dir%4 == 3 then intab.zpos = intab.zpos + 1 else print("Massive Error in intab.back()") end end return moveworked end function intab.up() local moveworked = turtle.up() if moveworked == true then intab.ypos = intab.ypos + 1 end return moveworked end function intab.down() local moveworked = turtle.down() if moveworked == true then intab.ypos = intab.ypos - 1 end return moveworked end function intab.turnLeft() local turnworked = turtle.turnLeft() if turnworked == true then intab.dir = intab.dir - 1 end return turnworked end function intab.turnRight() local turnworked = turtle.turnRight() if turnworked == true then intab.dir = intab.dir + 1 end return turnworked end function intab.printPos() print("Current Location: ("..intab.xpos..","..intab.ypos..","..intab.zpos..","..intab.dir%4..")") end function intab.getPos() currentPos = {"x"=intab.xpos,"y"=intab.ypos,"z"=intab.zpos,"dir"=intab.dir%4} return currentPos end function intab.calibrate(x,y,z,d) if type(x) == "table" then inputTable = x x = inputTable.x y = inputTable.y z = inputTable.z d = inputTable.d end if type(x) ~= "number" then x = 0 end if type(y) ~= "number" then y = 0 end if type(z) ~= "number" then z = 0 end if type(d) ~= "number" then d = 0 end intab.xpos = x intab.ypos = y intab.zpos = z intab.dpos = d end return intab end