View difference between Paste ID: e6uQxa8J and xDGNHWt8
SHOW: | | - or go back to the newest paste.
1
-- Open rednet on the modem side (adjust "left" as needed)
2
rednet.open("top")
3
4-
print("Waiting for coordinate broadcasts...")
4+
print("Waiting for coordinate broadcasts when redstone is active on the front...")
5
6
while true do
7-
    local senderID, message, protocol = rednet.receive("coordBroadcast")
7+
    -- Only process messages when redstone signal on the "front" is on.
8-
    
8+
    if redstone.getInput("front") then
9-
    if message and message.x and message.y and message.z then
9+
        -- Use a timeout (0.5 seconds) so the call doesn't block indefinitely and allows rechecking the redstone state.
10-
        print("Received coordinates from computer " .. senderID .. ":")
10+
        local senderID, message, protocol = rednet.receive("coordBroadcast", 0.5)
11-
        print("X: " .. message.x .. ", Y: " .. message.y .. ", Z: " .. message.z)
11+
        
12-
        -- Add any further processing of the coordinates here
12+
        if senderID then
13
            if message and message.x and message.y and message.z then
14-
        print("Received invalid data from computer " .. senderID)
14+
                print("Received coordinates from computer " .. senderID .. ":")
15
                print("X: " .. message.x .. ", Y: " .. message.y .. ", Z: " .. message.z)
16
            else
17
                print("Received invalid data from computer " .. senderID)
18
            end
19
        end
20
    else
21
        -- Optionally, you can print a message when redstone is off or simply sleep quietly.
22
        -- print("Redstone is off on the front; not receiving messages.")
23
        sleep(0.1)
24
    end
25
end
26