Guest User

Untitled

a guest
Jul 12th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. function gsplit2(s,sep)
  2. local lasti, done, g = 1, false, s:gmatch('(.-)'..sep..'()')
  3. return function()
  4. if done then return end
  5. local v,i = g()
  6. if s == '' or sep == '' then done = true return s end
  7. if v == nil then done = true return s:sub(lasti) end
  8. lasti = i
  9. return v
  10. end
  11. end
  12.  
  13. rednet.open( "right" )
  14.  
  15. while true do
  16. local sEvent, param1, param2 = os.pullEvent()
  17.  
  18. if sEvent == "rednet_message" then
  19. local p1,p2,p3,p4 = gsplit2(param2," ")
  20. if p1 == "go" then
  21. if p2 == "forward" then
  22. for i=1,p3 do
  23. turtle.forward()
  24. end
  25. elsif p2 == "back" then
  26. for i=1,p3 do
  27. turtle.back()
  28. end
  29. elsif p2 == "left" then
  30. turtle.turnLeft()
  31. for i=1,p3 do
  32. turtle.forward()
  33. end
  34. turtle.turnRight()
  35.  
  36. elsif p2 == "right" then
  37. turtle.turnRight()
  38. for i=1,p3 do
  39. turtle.forward()
  40. end
  41. turtle.turnLeft()
  42.  
  43. elsif p2 == "up" then
  44. for i=1,p3 do
  45. turtle.up()
  46. end
  47. elsif p2 == "down" then
  48. for i=1,p3 do
  49. turtle.down()
  50. end
  51. end
  52. elsif p1 == "excdia" then
  53. shell.run("excdia", p2)
  54. else
  55. print("Unknown command: "..p1.." "..p2.." "..p3)
  56. end
  57. end
  58.  
  59. if sEvent == "char" and param1 == "q" then
  60. break
  61. end
  62. end
  63.  
  64. rednet.close("right")
Add Comment
Please, Sign In to add comment