Advertisement
TyanColte

Untitled

Jan 7th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. shell.run("clear")                                  --Clears the turtle's screen
  2. print("Spacial Controls:")                          --Prints all the commands and their actions
  3. print("W/S = Forward/Back")
  4. print("A/D = Turn Left/Right")
  5. print("Space/Shift = Move Up/Down")
  6. print("")
  7. print("Other Commands:")
  8. print("ESC = Exit Program/Exit Turtle Interface")
  9. print("R = Refuel from any slot")
  10.                                                    
  11.                                                    --Defines the functions for the keys pressed
  12. function forward()
  13.   turtle.forward()
  14. end
  15.  
  16. function back()
  17.   turtle.back()
  18. end
  19.  
  20. function lt()
  21.   turtle.turnLeft()
  22. end
  23.  
  24. function rt()
  25.   turtle.turnRight()
  26. end
  27.  
  28. function up()
  29.   turtle.up()
  30. end
  31.  
  32. function down()
  33.   turtle.down()
  34. end
  35.  
  36. function refuel()
  37.   for i = 1, 16 do
  38.     turtle.select(i)
  39.     turtle.refuel(64)
  40.   end
  41. end
  42.  
  43. function terminate()
  44.   os.reboot()
  45. end
  46.  
  47. --Sets up a table for the key values and their respective function names.
  48. commands = {[17] = forward,  [31] = back,  [30] = lt,  [32] = rt, [57] = up, [42] = down, [19] = refuel, [1] = terminate}
  49.  
  50. --Starts the loop
  51. while true do
  52. local event, button = os.pullEvent("key") --Defines an event variable for the computer to wait for a keypress
  53. local fn = commands[button] --Defines a variable to get the index of the table based on the button pressed
  54.  
  55. --Checks to see if the fn variable is nil and if it's not run the variable fn as a function
  56.   if fn ~= nil then
  57.     fn()
  58.   end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement