Posted 27 August 2014 - 07:04 PM
This is yet another movement API that tracks position and facing of the turtle, but allows to give extensive movement instructions to a turtle in a simplified way.
Installation:
As always via pastebin then install as library:
Usage:
First initialize the turtle with the its position and facing:
Note: you can also use GPS if you have it like
If you do not supply the current position, the turtle will work with 0, 0, 0 as it's current position, which is usually sufficient for most tasks.
If you do not initialize the position, the code will still work, but turn() most likely won't work as expected.
You can then either call the commands directly via:
If properly initialized you can query the turtle's location via getPosition() or getDirection() and as well have the turtle turn into a specific direction:
Or you can supply a series of movement instructions as string:
This not only allows you to enter complex movement in a single and simple string, but as well makes remote control of a turtle much easier, because you pad only has to transmit a single string!
A movement string can be composed of valid commands separated by space and optionally a number that will cause the next command to be repeated that many times (if appropriate). Only movement and turn commands can be repeated, repeated digging till no further block can be digged is already part of the digging functionality.
The syntax is:
You can find a list of all possible commands in the table COMMANDS in the file. There are as well some further utility functions that I have not documented here.
ToDo:
This library is not yet completed, here are some things I plan to do in the future:
I welcome any suggestions, bug reports or ideas for improvement.
Installation:
As always via pastebin then install as library:
pastebin get wjz8auP1 tmove
os.loadAPI("tmove")
Usage:
First initialize the turtle with the its position and facing:
tmove.setPosition("north", 24, 80, 133)
Note: you can also use GPS if you have it like
tmove.setPosition("north", gps.locate(5))
If you do not supply the current position, the turtle will work with 0, 0, 0 as it's current position, which is usually sufficient for most tasks.
tmove.setPosition("north")
If you do not initialize the position, the code will still work, but turn() most likely won't work as expected.
You can then either call the commands directly via:
tmove.COMMANDS.f(2) -- moves forward by 2 steps
If properly initialized you can query the turtle's location via getPosition() or getDirection() and as well have the turtle turn into a specific direction:
tmove.turn("south") -- turns to look south
Or you can supply a series of movement instructions as string:
tmove.move("2 d3md 8 d3mf r d3mf r 8 d3mf l d3mf l")
This example will cause the turtle to dig down 2 blocks, then dig a line of 8 blocks, digs a step to the right, digs the 8 blocks back and gets into position for another round. This not only allows you to enter complex movement in a single and simple string, but as well makes remote control of a turtle much easier, because you pad only has to transmit a single string!
A movement string can be composed of valid commands separated by space and optionally a number that will cause the next command to be repeated that many times (if appropriate). Only movement and turn commands can be repeated, repeated digging till no further block can be digged is already part of the digging functionality.
The syntax is:
f - step forward
b - step backward
u - step up
d - step up
r - turn right
l - turn left
d... - dig as instructed by ... Example: df - dig forward. dfu - dig forward and up. d3 - dig in all 3 directions.
d...m... - a combination of digging and movement, where d... is as above and the ... after m is one of f, b, u, d.
You can find a list of all possible commands in the table COMMANDS in the file. There are as well some further utility functions that I have not documented here.
ToDo:
This library is not yet completed, here are some things I plan to do in the future:
- Find a way to compensate if movement fails.
- Have some form of path-finding in the form of moveTo(location).
- Add placement of blocks from a slot as commands.
- Handle chunk-loading and shutdowns properly
I welcome any suggestions, bug reports or ideas for improvement.
Edited on 27 August 2014 - 08:23 PM