Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 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 coord()
  11. print("Position: "..posx.." / "..posy)
  12. end
  13.  
  14. function iposx()
  15. posx = posx + 1
  16. end
  17.  
  18. function iposy()
  19. posy = posy + 1
  20. end
  21.  
  22. function dposx()
  23. posx = posx - 1
  24. end
  25.  
  26. function dposy()
  27. posy = posy - 1
  28. end
  29.  
  30. function mine()
  31.     print("doing stuff here")
  32. end
  33.  
  34. function move(dx, dy)
  35.     moveDirX(posx, dx)
  36.     moveDirY(posy, dy)
  37. end
  38.  
  39. function moveDirX(ax, dx)
  40.     if ax == 0 then step(dx, 1) else
  41.         delta = ax-dx
  42.         if delta < 0 then step(delta, 0)
  43.         elseif delta > 0 then step(delta, 0)      
  44.         else print("Nothing to do in X-Direction")
  45.         end
  46.     end
  47. end
  48.  
  49. function moveDirY(ay, dy)
  50.     if ay == 0 then step(dy, 1) else
  51.         delta = ay-dy
  52.         if delta < 0 then step(delta, 1)
  53.         elseif delta > 0 then step(delta, 1)
  54.         else print("Nothing to do in X-Direction")
  55.         end
  56.     end
  57. end
  58.  
  59. function betrag(zahl1)
  60.     if zahl1 < 0 then return zahl1 * -1
  61.     else return zahl1
  62.     end
  63. end
  64.  
  65. function step(count, axis)
  66.     if axis == 0 then
  67.         if count > 0 then
  68.             moveRight(betrag(count))
  69.             return true
  70.         elseif count < 0 then
  71.             moveLeft(betrag(count))
  72.             return true
  73.         end
  74.     elseif axis == 1 then
  75.         if count > 0 then
  76.             moveForward(betrag(count))
  77.             return true
  78.         elseif count < 0 then
  79.             moveBack(betrag(count))
  80.             return true
  81.         end
  82.     end
  83.    
  84. end
  85.  
  86. function moveRight(ci)
  87.     turtle.turnRight(1)
  88.         for i=1, ci do
  89.             print("Moving right. New: "..(posx+1).." / "..posy)
  90.             if not turtle.detect() then
  91.                 turtle.forward()
  92.                 iposx()
  93.             else print("I crashed right!")
  94.             end
  95.         end
  96.     turtle.turnLeft(1)
  97. end
  98.  
  99. function moveLeft(ci)
  100.     turtle.turnLeft(1)
  101.         for i=1, ci do
  102.             print("Moving left. New: "..(posx-1).." / "..posy)
  103.             if not turtle.detect() then
  104.                 turtle.forward()
  105.                 dposx()
  106.             else print("I crashed left!"
  107.             end
  108.         end
  109.     turtle.turnRight(1)
  110. end
  111.  
  112. function moveForward(ci)
  113.     for i=1, ci do
  114.         print("Moving forward. New: "..posx.." / "..(posy+1))
  115.         if not turtle.detect() then
  116.             turtle.forward()
  117.             iposy()
  118.         else print("I crashed forward!")
  119.         end
  120.     end
  121. end
  122.  
  123. function moveBack(ci)
  124.     turtle.turnRight(2)
  125.     for i=1, ci do
  126.         print("Moving back. New: "..posx.." / "..(posy-1))
  127.         if not turtle.detect() then
  128.             turtle.forward()
  129.             dposy()
  130.         else print("I crashed backward!")
  131.         end
  132.     end
  133.     turtle.turnRight(2)
  134. end
  135.  
  136.  
  137.  
  138.  
  139. if not waitafter then sleep(wait) end
  140. --.....
  141. move(1,1)
  142. move(1,1)
  143. if waitafter then sleep(wait) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement