Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear") --Clears the turtle's screen
- print("Spacial Controls:") --Prints all the commands and their actions
- print("W/S = Forward/Back")
- print("A/D = Turn Left/Right")
- print("Space/Shift = Move Up/Down")
- print("")
- print("Other Commands:")
- print("ESC = Exit Program/Exit Turtle Interface")
- print("R = Refuel from any slot")
- --Defines the functions for the keys pressed
- function forward()
- turtle.forward()
- end
- function back()
- turtle.back()
- end
- function lt()
- turtle.turnLeft()
- end
- function rt()
- turtle.turnRight()
- end
- function up()
- turtle.up()
- end
- function down()
- turtle.down()
- end
- function refuel()
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel(64)
- end
- end
- function terminate()
- os.reboot()
- end
- --Sets up a table for the key values and their respective function names.
- commands = {[17] = forward, [31] = back, [30] = lt, [32] = rt, [57] = up, [42] = down, [19] = refuel, [1] = terminate}
- --Starts the loop
- while true do
- local event, button = os.pullEvent("key") --Defines an event variable for the computer to wait for a keypress
- local fn = commands[button] --Defines a variable to get the index of the table based on the button pressed
- --Checks to see if the fn variable is nil and if it's not run the variable fn as a function
- if fn ~= nil then
- fn()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement