Advertisement
Guest User

GPSa08

a guest
Oct 20th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. if posx == nil then posx = 1 end
  2. if posy == nil then posy = 0 end
  3.  
  4. if fieldx == nil then fieldx = 9 end
  5. if fieldy == nil then fieldy = 9 end
  6.  
  7. if wait == nil then wait = 5 end
  8. if waitafter == nil then waitafter = true end
  9.  
  10. function mine()
  11.     print("doing stuff here")
  12. end
  13.  
  14. function move(dx, dy)
  15.     moveDirX(posx, dx)
  16.     moveDirY(posy, dy)
  17. end
  18.  
  19. function moveDirX(ax, dx)
  20.     delta = ax-dx
  21.     if delta < 0 then step(delta, 0)
  22.       elseif delta > 0 then step(delta, 0)       else print("Nothing to do in X-Direction")
  23.     end
  24. end
  25.  
  26. function moveDirY(ay, dy)
  27.     delta = ay-dy
  28.     if delta < 0 then step(delta, 1)
  29.     elseif delta > 0 then step(delta, 1)
  30.     else print("Nothing to do in X-Direction")
  31.     end
  32. end
  33.  
  34. function betrag(zahl1)
  35.     if zahl1 < 0 then return zahl1 * -1
  36.     else return zahl1
  37.     end
  38. end
  39.  
  40. function step(count, axis)
  41.     if axis == 0 then
  42.         for i=1, betrag(count) do
  43.             if count > 0 then
  44.                 moveRight()
  45.                 return true
  46.             elseif count < 0 then
  47.                 moveLeft()
  48.                 return true
  49.             end
  50.         end
  51.     elseif axis == 1 then
  52.         for i=1, betrag(count) do
  53.             if count > 0 then
  54.                 moveForward()
  55.                 return true
  56.             elseif count < 0 then
  57.                 moveBack()
  58.                 return true
  59.             end
  60.         end
  61.     end
  62.    
  63. end
  64.  
  65. function moveRight()
  66. --    print("Moving to the right. New coordinates should be: "..posx+1.." / "..posy)
  67. end
  68.  
  69. function moveLeft()
  70. --    print("Moving to the right. New coordinates should be: "..posx-1.." / "..posy)
  71. end
  72.  
  73. function moveForward()
  74.     print("Moving to the right. New coordinates should be: "..posx.." / "..(posy+1))
  75. end
  76.  
  77. function moveBack()
  78. --    print("Moving to the right. New coordinates should be: "..posx.." / "..posy-1)
  79. end
  80.  
  81.  
  82.  
  83.  
  84. if not waitafter then sleep(wait) end
  85. --.....
  86. move(1,1)
  87.  
  88. if waitafter then sleep(wait) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement