Advertisement
justync7

remoteturtle

Jun 29th, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. rednet.open("left")
  2. function split(str, pat)
  3. local t = {} -- NOTE: use {n = 0} in Lua-5.0
  4. local fpat = "(.-)" .. pat
  5. local last_end = 1
  6. local s, e, cap = str:find(fpat, 1)
  7. while s do
  8. if s ~= 1 or cap ~= "" then
  9. table.insert(t,cap)
  10. end
  11. last_end = e+1
  12. s, e, cap = str:find(fpat, last_end)
  13. end
  14. if last_end <= #str then
  15. cap = str:sub(last_end)
  16. table.insert(t, cap)
  17. end
  18. return t
  19. end
  20.  
  21. while true do
  22. id, message = rednet.receive()
  23. if split(message," ")[1] == "forward" then
  24. times=tonumber(split(message," ")[2])
  25. for i=1,times do
  26. turtle.forward()
  27. end
  28. elseif split(message," ")[1] == "up" then
  29. times=tonumber(split(message," ")[2])
  30. for i=1,times do
  31. turtle.up()
  32. end
  33. elseif split(message," ")[1] == "down" then
  34. times=tonumber(split(message," ")[2])
  35. for i=1,times do
  36. turtle.down()
  37. end
  38. elseif message == "left" then
  39. turtle.turnLeft()
  40. elseif message == "right" then
  41. turtle.turnRight()
  42. elseif split(message," ")[1] == "back" then
  43. times=tonumber(split(message," ")[2])
  44. for i=1,times do
  45. turtle.back()
  46. end
  47. elseif split(message," ")[1] == "shutdown" then
  48. pc = peripheral.wrap(split(message," ")[2])
  49. pc.shutdown()
  50. elseif split(message," ")[1] == "reboot" then
  51. pc = peripheral.wrap(split(message," ")[2])
  52. pc.reboot()
  53. elseif split(message," ")[1] == "turnon" then
  54. pc = peripheral.wrap(split(message," ")[2])
  55. pc.turnOn()
  56. end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement