mariebu

Bewege Turtle

Mar 26th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. -- Bewegen der Turtle mehrschrittig
  2.  
  3. -- Vorgabewerte erfragen
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. print("Wie viele Schritte soll die Turtle bewegt werden?")
  7. stepAmount = io.read()
  8. print("In welche Richtung soll die Turtle die Schritte gehen?")
  9. print("[v]orwärts [l]inks [r]echts [z]urück")
  10. direction = io.read()
  11.  
  12. stepAmount = stepAmount + 0
  13.  
  14. -- Brennmaterialbedarf ermitteln und befüllen
  15. function fuelCheck()
  16.   local fuelNeed = stepAmount
  17.   local currentFuel = turtle.getFuelLevel()
  18.   if currentFuel < fuelNeed then
  19.     print("Zu wenig Treibstoff. " .. currentFuel .. "/" .. fuelNeed)
  20.     print("Bitte Slot angeben in dem der Treibstoff liegt:")
  21.     local k = io.read()
  22.     k = k + 0
  23.     turtle.select(k)
  24.     turtle.refuel()
  25.     sleep(0.5)
  26.     fuelCheck()
  27.   else
  28.     print("Treibstoffbedarf gedeckt: " .. currentFuel .. "/" .. fuelNeed)
  29.     sleep(0.5)
  30.   end
  31. end
  32.  
  33. fuelCheck()
  34.  
  35. -- rückwärts
  36. if direction == "z" then
  37.   for i=1,stepAmount do
  38.     turtle.back()
  39.   end
  40. end
  41. -- links
  42. if direction == "l" then
  43.   turtle.turnLeft()
  44.   direction = "v"
  45. end
  46. -- rechts
  47. if direction == "r" then
  48.   turtle.turnRight()
  49.   direction = "v"
  50. end
  51. -- vorwärts
  52. if direction == "v" then
  53.   for i=1,stepAmount do
  54.     turtle.forward()
  55.   end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment