Posted 31 May 2014 - 03:48 AM
This is the XT API. I keep rewriting it every time I've got to use it, so I decided to polish it up a little and upload it.
Now, even though the name is XtraTurtle, it´s not only for turtles, it´s also got a wireless part which can be used in computers.
Briefly, the features of this API are:
V1.2
V1.1
V1.0
RELAY:
V1.0
So, full documentation:
WIRELESS PART:
Will replace the rednet with the XT relaying events(xt.run). rednet.receive() will not work until xt.finish() is called.
-xt.finish()
Will stop xt.run and restore the rednet if xt.replaceRednet was used to start it.
-xt.run()
Needs to be run in parallel with your programs with the parallel API. Wrap your code in a function and then do:
-xt.connectModem()
Will connect a modem if connected to the computer. It will prefer wireless ones before wired ones, to allow things such as connecting alot of computers to one wireless modem. The connected modem is stored in xt.modem.
-xt.openChannel(number channel)
Will open the channel in the currently connected modem. It will open a modem if none is open. It will also open the channel for all connected relays.
-xt.transmit(number channel,number replyChannel,table payload)
Will send a TABLE (pay attention, table) through the relays.
TURTLE PART:
Amount is optional and can be negative, defaults to 1. It will go forward amount spaces. If negative will go the other way amount spaces.
-xt.bk(amount)
Amount is optional and can be negative, defaults to 1. It will go back amount spaces. If negative will go the other way amount spaces.
-xt.up(amount)
Amount is optional and can be negative, defaults to 1. It will go up amount spaces. If negative will go the other way amount spaces.
-xt.dn(amount)
Amount is optional and can be negative, defaults to 1. It will go down amount spaces. If negative will go the other way amount spaces.
-xt.left(amount)
Amount is optional and can be negative, defaults to 1. It will turn left amount times. If negative will go the other way amount spaces.
-xt.right(amount)
Amount is optional and can be negative, defaults to 1. It will turn right amount spaces. If negative will go the other way amount spaces.
-xt.sel(slot)
It will select the turtle´s slot slot.
-xt.locate()
Will try to use the GPS to update the position.
Returns true if it could or false if it couldn’t.
-xt.calibrate()
Will try to use GPS to update facing. Will also update the position in the process.
Returns true if it could update or false if it couldn´t.
Requires an empty space in front or behind the turtle. Also requires 2 fuel units.
-xt.face(nf)
nf is needed. It is the direction to face.
This will face nf the quickliest way possible.
-xt.invertFace(f)
f is optional. Defaults to xt.f.
This will return the facing opposite to the f passed in.
xt.face(xt.invertFace()) will do a turn-around.
-xt.gotoX(nx)
nx is needed. It is the x-coordinate to go.
This will go to the specified X coordinate.
-xt.gotoY(ny)
ny is needed. It is the y-coordinate to go.
This will go to the specified Y coordinate.
-xt.gotoZ(nz)
nz is needed. It is the z-coordinate to go.
This will go to the specified Z coordinate.
Also every function the turtle api has xt will have, just use the same name.
EG: turtle.getFuelLevel==xt.getFuelLevel
You are free to edit, crop, add, modify, delete, etc any part of the API, but please don't delete that little first line "XT by negamartin"
Sorry if my grammar/spelling is not correct, english is not my first language.
Now, even though the name is XtraTurtle, it´s not only for turtles, it´s also got a wireless part which can be used in computers.
Briefly, the features of this API are:
- Position/orientation tracking and autosaving. Autosave will save every time it moves the position to the disk in case of shutdowns. It can be disabled.
- Utility functions to face and go to positions
- Relaying messages with Relays to extend modem range.
- Calibrating turtle's position and angle if in range of GPS
Spoiler
XT API:V1.2
*Fixed error in position awarement.
Run in CraftOS shell with http enabled:
pastebin get zCXeSLkA xt
V1.1
*Changed relayed_message to give payload as table instead of string.
+Now the XT special functions replace the turtle's. To disable set replaceTurtle to false before loading. Original functions are in turtle.orig.
Run in CraftOS shell with http enabled:
pastebin get T3cgQ5ib xt
V1.0
Run in CraftOS shell with http enabled:
pastebin get VXdZghFj xt
RELAY:
V1.0
Run in CraftOS shell with htp enabled:
pastebin get AHNTNntv startup
So, full documentation:
WIRELESS PART:
Spoiler
-xt.replaceRednet()Will replace the rednet with the XT relaying events(xt.run). rednet.receive() will not work until xt.finish() is called.
-xt.finish()
Will stop xt.run and restore the rednet if xt.replaceRednet was used to start it.
-xt.run()
Needs to be run in parallel with your programs with the parallel API. Wrap your code in a function and then do:
function main()
--Your code here
end
parallel.waitForAny(main,xt.run);
It will produce the "relayed_message" event for relaying.-xt.connectModem()
Will connect a modem if connected to the computer. It will prefer wireless ones before wired ones, to allow things such as connecting alot of computers to one wireless modem. The connected modem is stored in xt.modem.
-xt.openChannel(number channel)
Will open the channel in the currently connected modem. It will open a modem if none is open. It will also open the channel for all connected relays.
-xt.transmit(number channel,number replyChannel,table payload)
Will send a TABLE (pay attention, table) through the relays.
TURTLE PART:
Spoiler
-xt.fw(amount)Amount is optional and can be negative, defaults to 1. It will go forward amount spaces. If negative will go the other way amount spaces.
-xt.bk(amount)
Amount is optional and can be negative, defaults to 1. It will go back amount spaces. If negative will go the other way amount spaces.
-xt.up(amount)
Amount is optional and can be negative, defaults to 1. It will go up amount spaces. If negative will go the other way amount spaces.
-xt.dn(amount)
Amount is optional and can be negative, defaults to 1. It will go down amount spaces. If negative will go the other way amount spaces.
-xt.left(amount)
Amount is optional and can be negative, defaults to 1. It will turn left amount times. If negative will go the other way amount spaces.
-xt.right(amount)
Amount is optional and can be negative, defaults to 1. It will turn right amount spaces. If negative will go the other way amount spaces.
-xt.sel(slot)
It will select the turtle´s slot slot.
-xt.locate()
Will try to use the GPS to update the position.
Returns true if it could or false if it couldn’t.
-xt.calibrate()
Will try to use GPS to update facing. Will also update the position in the process.
Returns true if it could update or false if it couldn´t.
Requires an empty space in front or behind the turtle. Also requires 2 fuel units.
-xt.face(nf)
nf is needed. It is the direction to face.
This will face nf the quickliest way possible.
-xt.invertFace(f)
f is optional. Defaults to xt.f.
This will return the facing opposite to the f passed in.
xt.face(xt.invertFace()) will do a turn-around.
-xt.gotoX(nx)
nx is needed. It is the x-coordinate to go.
This will go to the specified X coordinate.
-xt.gotoY(ny)
ny is needed. It is the y-coordinate to go.
This will go to the specified Y coordinate.
-xt.gotoZ(nz)
nz is needed. It is the z-coordinate to go.
This will go to the specified Z coordinate.
Also every function the turtle api has xt will have, just use the same name.
EG: turtle.getFuelLevel==xt.getFuelLevel
You are free to edit, crop, add, modify, delete, etc any part of the API, but please don't delete that little first line "XT by negamartin"
Sorry if my grammar/spelling is not correct, english is not my first language.
Edited on 21 December 2014 - 07:47 PM