Advertisement
poboivin

Goto

Oct 3rd, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. function AtPos(gx,gy,gz)
  2. print("checking pos")
  3. cx,cy,cz = gps.locate(1,false)
  4. if cx == gx and cy == gy and cz == gz then
  5. return true
  6. else
  7. return false
  8. end
  9. end
  10.  
  11. tArgs = { ...}
  12. gx=tonumber(tArgs[1])
  13. gy=tonumber(tArgs[2])
  14. gz=tonumber(tArgs[3])
  15. cx,cy,cz = gps.locate(1,false)
  16.        
  17.         print("I am at "..cx..":x "..cy..":y "..cz..":z")
  18.         print("goint to "..gx..":x "..gy..":y "..gz..":z")
  19.        -- print(cz)
  20.        -- print(cz+1)
  21.        print("debug1")
  22.         while AtPos(gx,gy,gz) == false do
  23.         print("debug2")    
  24.        
  25.         if cz > gz then -- too far north
  26.                         shell.run('Turn',2)
  27.                         print("facing south")
  28.                         print("moving "..math.abs(cz-gz).."meters")
  29.                        shell.run('GoForward',(math.abs(cz-gz))) --go south
  30.                        
  31.         elseif cz < gz then -- too far south
  32.                         shell.run('Turn',0)
  33.                         print("facing north")
  34.                         print("moving "..math.abs(cz-gz).."meters")
  35.                         shell.run('GoForward',(math.abs(cz-gz))) -- go north
  36.         end
  37.         if cx > gx then -- to far west
  38.                         shell.run('Turn',(1))
  39.                         print("facing west")
  40.                         print("moving "..math.abs(cx-gx).."meters")
  41.                         shell.run('GoForward',(math.abs(cx-gx))) -- go e or w
  42.         elseif cx < gx then -- too far east
  43.                         shell.run('Turn',(3))
  44.                         print("facing east")
  45.                         print("moving "..math.abs(cx-gx).."meters")
  46.                         shell.run('GoForward',(math.abs(cx-gx))) -- go e or w
  47.         end
  48.         if cy > gy then
  49.                         print("moving down")
  50.                         turtle.down()
  51.                         cx,cy,cz = gps.locate(1,false)
  52.        
  53.        
  54.         elseif cy < gy then
  55.                         print("moving up")
  56.                         turtle.up()
  57.                        cx,cy,cz = gps.locate(1,false)
  58.         end
  59.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement