Savage_Me55iah

remote control

Jun 11th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1.  
  2. turtle_num = 492
  3.  
  4. function find_peripheral(t, e)
  5. e = e or nil
  6. sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
  7. peripheral_found = false
  8. for num=1, 6 do
  9. type = peripheral.getType(sides[num])
  10. if type == t then
  11. if e == "wireless" then
  12. if peripheral.call(sides[num], "isWireless") then
  13. return sides[num]
  14. end
  15. elseif e == "remote" then
  16. if not peripheral.call(sides[num], "isWireless") then
  17. return sides[num]
  18. end
  19. elseif e == nil then
  20. return sides[num]
  21. end
  22. end
  23. end
  24. print("No " .. t .. " attached to the computer")
  25. end
  26.  
  27. function button_draw(number, ypos)
  28. term.setCursorPos(1, ypos)
  29. x, button[number] = term.getCursorPos()
  30. if names[number] ~= nil then
  31. text = names[number]:upper()
  32. term.write(" " .. text .. " ")
  33. end
  34. end
  35.  
  36. function select_button()
  37. z = 1
  38. button_pressed = nil
  39. repeat
  40. if names[z] ~= nil then
  41. if y == button[z] then
  42. return z
  43. end
  44. end
  45. z = z + 1
  46. until z > table.maxn(names)
  47. end
  48.  
  49. names = {[1] = "up", [2] = "down", [3] = "forward", [4] = "back", [5] = "t left", [6] = "t right", [7] = "place", [8] = "dig", [9] = "suck", [10] = "drop", [11] = "unload", [12] = "inv 1", [13] = "inv 16"}
  50. button = {}
  51. rednet.open(find_peripheral(modem, wireless)
  52.  
  53. function draw()
  54. term.clear()
  55. for num=1,table.maxn(names) do
  56. button_draw(num, num)
  57. end
  58.  
  59. while true do
  60. e, i, x, y = os.pullEvent()
  61. num = select_button()
  62. if num ~= nil then
  63. rednet.send(turtle_num, names[num])
  64. end
  65. draw()
  66. end
Advertisement
Add Comment
Please, Sign In to add comment