Advertisement
SkyFlash21

red

Jul 21st, 2021 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. local function turtleFunc()
  2. while true do
  3. turtle.turnLeft()
  4. end
  5. end
  6.  
  7. local turtleCoroutine = coroutine.create(turtleFunc)
  8. coroutine.resume(turtleCoroutine) --# The function needs no parameters for its first resume.
  9.  
  10. local function rednetFunc()
  11. while true do
  12. local sender, message = rednet.receive(1)
  13. print(message)
  14. --# Maybe do something with the message here.
  15. end
  16. end
  17.  
  18. local rednetCoroutine = coroutine.create(rednetFunc)
  19. coroutine.resume(rednetCoroutine)
  20.  
  21. while true do
  22. local myEvent = { os.pullEvent() }
  23.  
  24. if myEvent[1] == "turtle_response" then
  25. coroutine.resume( turtleCoroutine, unpack( myEvent ) ) --# See http://www.lua.org/pil/5.1.html regarding unpack
  26.  
  27. elseif myEvent[1] == "rednet_message" or myEvent[1] == "timer" then
  28. coroutine.resume( rednetCoroutine, unpack( myEvent ) )
  29.  
  30. end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement