Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Open rednet on the modem side (adjust "left" as needed)
- rednet.open("top")
- print("Waiting for coordinate broadcasts when redstone is active on the front...")
- while true do
- -- Only process messages when redstone signal on the "front" is on.
- if redstone.getInput("front") then
- -- Use a timeout (0.5 seconds) so the call doesn't block indefinitely and allows rechecking the redstone state.
- local senderID, message, protocol = rednet.receive("coordBroadcast", 0.5)
- if senderID then
- if message and message.x and message.y and message.z then
- print("Received coordinates from computer " .. senderID .. ":")
- print("X: " .. message.x .. ", Y: " .. message.y .. ", Z: " .. message.z)
- else
- print("Received invalid data from computer " .. senderID)
- end
- end
- else
- -- Optionally, you can print a message when redstone is off or simply sleep quietly.
- -- print("Redstone is off on the front; not receiving messages.")
- sleep(0.1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement