100 posts
Posted 24 January 2013 - 06:55 PM
i'm trying to see if theres a way to get the magicturtle api to use my gps system? all my computers and turtles now say they need their position set and i was hoping i could run a simple script?
1548 posts
Location
That dark shadow under your bed...
Posted 25 January 2013 - 01:51 AM
sorry to post a question in response to your question but what is magicturtle api? I have never seen it
can't you just use the normal GPS api?
100 posts
Posted 25 January 2013 - 06:03 AM
hey no problem at all.
magicturtle is an api that adds a lot of functionality to the turtle that i'm interested in using.
heres a linkit asks that you set its position, for every turtle, but i'm hoping i can find a way to get it to use its GPS to get its location.
idk how i'd use the GPS api to tell the MT API where its coordinates are.
1548 posts
Location
That dark shadow under your bed...
Posted 25 January 2013 - 07:05 AM
here is the code:
local pos={}
for i=1,2 do
turtle[i==1 and "back" or "forward"]()
pos[i]={gps.locate(2)}
if not pos[i][1] then error("could not get GPS co-ordinates")
end
mt.setPos(unpack(pos[2]))
mt.setFacing(pos[1][1]>pos[2][1] and 1 or pos[1][1]<pos[2][1] and 3 or pos[1][3]>pos[2][3] and 0 or pos[1][3]<pos[2][3] and 2)
just make sure there is an empty space behind the turtle.
basically we make it move back one block, get its position, move forward one block and get it again (we do this to find out direction)
the second saved position is our current position so we send that position to mt.setPos()
if we compare the 2 positions and find that the first x position is higher than the second x position we know we are facing the -x direction (west f:1) and so forth. we then pass that to the mt.setFacing() function