Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 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)      
  23.     else print("Nothing to do in X-Direction")
  24.     end
  25. end
  26.  
  27. function moveDirY(ay, dy)
  28.     delta = ay-dy
  29.     if delta < 0 then step(delta, 1)
  30.     elseif delta > 0 then step(delta, 1)
  31.     else print("Nothing to do in X-Direction")
  32.     end
  33. end
  34.  
  35. function betrag(zahl1)
  36.     if zahl1 < 0 then return zahl1 * -1
  37.     else return zahl1
  38.     end
  39. end
  40.  
  41. function step(count, axis)
  42.     if axis == 0 then
  43.         if count > 0 then
  44.             moveRight(betrag(count))
  45.             return true
  46.         elseif count < 0 then
  47.             moveLeft(betrag(count))
  48.             return true
  49.         end
  50.     elseif axis == 1 then
  51.         if count > 0 then
  52.             moveForward(betrag(count))
  53.             return true
  54.         elseif count < 0 then
  55.             moveBack(betrag(count))
  56.             return true
  57.         end
  58.     end
  59.    
  60. end
  61.  
  62. function moveRight(ci)
  63.     turtle.turnRight(1)
  64.         for i=1, ci do
  65.             print("Moving right. New: "..(posx+1).." / "..posy)
  66.             if not turtle.detect() then turtle.forward() else print("I crashed right!") end
  67.         end
  68.     turtle.turnLeft(1)
  69. end
  70.  
  71. function moveLeft(ci)
  72.     turtle.turnLeft(1)
  73.         for i=1, ci do
  74.             print("Moving left. New: "..(posx-1).." / "..posy)
  75.             if not turtle.detect() then turtle.forward() else print("I crashed left!") end
  76.         end
  77.     turtle.turnRight(1)
  78. end
  79.  
  80. function moveForward(ci)
  81.     for i=1, ci do
  82.         print("Moving forward. New: "..posx.." / "..(posy+1))
  83.         if not turtle.detect() then turtle.forward() else print("I crashed forward!") end
  84.     end
  85. end
  86.  
  87. function moveBack(ci)
  88.     turtle.turnRight(2)
  89.     for i=1, ci do
  90.         print("Moving back. New: "..posx.." / "..(posy-1))
  91.         if not turtle.detect() then turtle.forward() else print("I crashed backward!") end
  92.     end
  93.     turtle.turnRight(2)
  94. end
  95.  
  96.  
  97.  
  98.  
  99. if not waitafter then sleep(wait) end
  100. --.....
  101. move(1,1)
  102.  
  103. if waitafter then sleep(wait) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement