Advertisement
aharries

Startup -- Computer

Apr 17th, 2024 (edited)
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. -- Load the Rednet API
  2. rednet.open("back")
  3.  
  4. print("Enter the ID of the turtle:")
  5. local turtle_id = tonumber(read())
  6.  
  7. print("Enter the size of the excavation area:")
  8. local size = tonumber(read())
  9.  
  10. -- Sending the excavate command to the specified turtle
  11. rednet.send(turtle_id, "excavate " .. size)
  12.  
  13. print("Excavation command sent to turtle " .. turtle_id .. " for a size of " .. size)
  14.  
  15. -- Function to receive messages from the turtle
  16. function receiveMessages()
  17.     while true do
  18.         local id, message = rednet.receive()
  19.         if id == turtle_id then
  20.             print("Turtle " .. id .. ": " .. message)
  21.         end
  22.     end
  23. end
  24.  
  25. -- Run the receiveMessages function in parallel
  26. parallel.waitForAny(receiveMessages, function()
  27.     print("Press any key to stop receiving messages.")
  28.     os.pullEvent("key")  -- Wait for a key press
  29.     error("Stopped by user")  -- Force the parallel loop to terminate
  30. end)
  31.  
  32. -- Close the Rednet API
  33. rednet.close("back")
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement