Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getturtlepos()
- local ch -- sets a var for the direction the turtle is facing
- rednet.open("right") -- opens the modem
- local cx,cy,cz = gps.locate(10) -- gets the turtles position
- turtle.forward() -- moves the turtle forward 1 space
- local fx,fy,fz = gps.locate(10) -- gets the turtles position
- turtle.back() -- moves the turtle back to its original position
- rednet.close("right") -- closes the modem
- if fx > cx then --if final X is Greater than original X turtle is facing East
- ch = 3 --East
- elseif fx < cx then --if final X is Less than original X turtle is facing West
- ch = 1 --West
- elseif fz > cz then --if final Z is Greater than original Z turtle is facing South
- ch = 4 --South
- elseif fz < cz then --if final Z is Less than original Z turtle is facing North
- ch = 2 --North
- end
- return cx , cy , cz , ch -- returns position and heading info
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement