Guest User

PDA.lua

a guest
Apr 17th, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. --GoldKart (c) GoldProgramming 2014
  2. --PDA Version 1.0
  3. --Csstform
  4.  
  5. --CONFIG
  6. --===================
  7. --TURTLE ID
  8. local tNum = 1
  9. --===================
  10. --KEY BINDINGS
  11. --===================
  12. --FORWARD
  13. local forward = 17 --(default: 17)
  14. --BACKWARD
  15. local backward = 31 --(default: 31)
  16. --LEFT
  17. local left = 30 --(default: 30)
  18. --RIGHT
  19. local right = 32 --(default: 32)
  20. --PICK UP ITEM
  21. local getItem = 16 --(default: 16)
  22. --USE ITEM
  23. local useItem = 18 --(default: 18)
  24. --ESC KEY
  25. local exitKey = 19 --(default: 19)
  26. --===================
  27.  
  28. --Program initialzation
  29. rednet.open("back")
  30. local exit = false
  31. local x,y = term.getSize()
  32. term.clear()
  33.  
  34. --Draw instruction box
  35. for i=1, y do
  36.     term.setCursorPos(1, i)
  37.     write("|")
  38.     term.setCursorPos(x, i)
  39.     write("|")
  40. end
  41. for i=1, x do
  42.     term.setCursorPos(i, y)
  43.     write("-")
  44.     term.setCursorPos(i, 1)
  45.     write("-")
  46. end
  47. term.setCursorPos(2, 2)
  48. write("Use WASD to move")
  49. term.setCursorPos(2, 3)
  50. write("your turtle.")
  51. term.setCursorPos(2, 4)
  52. write("Q = Get item")
  53. term.setCursorPos(2, 5)
  54. write("E = Use item")
  55. term.setCursorPos(2, 6)
  56. write("R = Quit")
  57.  
  58. --This will grab input from the user
  59. function getInput()
  60.     local _,input = os.pullEvent("key")
  61.     return input
  62. end
  63.  
  64. --This will send a command to the turtle
  65. function sendCommand(command)
  66.     rednet.send(tNum, command)
  67. end
  68.  
  69. --this will translate the user's input into a string to be sent over rednet
  70. function readCommand(input)
  71.     if input == forward then
  72.         return "forward"
  73.     elseif input == left then
  74.         return "left"
  75.     elseif input == backward then
  76.         return "down"
  77.     elseif input == right then
  78.         return "right"
  79.     elseif input == getItem then
  80.         return "getItem"
  81.     elseif input == useItem then
  82.         return "useItem"
  83.     elseif input == exitKey then
  84.         exit = true
  85.         return "exit"
  86.     end
  87. end
  88.  
  89. --Main program loop
  90. while exit == false do
  91.     input = getInput()
  92.  
  93.     command = readCommand(input)
  94.     sendCommand(command)
  95. end
  96.  
  97. --Closing code
  98. term.clear()
  99. term.setCursorPos(1, 1)
  100. rednet.close("back")
Advertisement
Add Comment
Please, Sign In to add comment