fix: Refactor message handling to improve status updates and server communication
This commit is contained in:
@@ -60,16 +60,15 @@ end
|
|||||||
while true do
|
while true do
|
||||||
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||||
|
|
||||||
|
-- Only process messages on our channels
|
||||||
|
if channel == STATUS_CHANNEL or channel == CHANNEL_RECEIVE then
|
||||||
print("Received modem message on channel " .. channel)
|
print("Received modem message on channel " .. channel)
|
||||||
|
|
||||||
if type(message) == "table" then
|
if type(message) == "table" then
|
||||||
print(" Message type: " .. (message.type or "no type"))
|
print(" Message type: " .. (message.type or "no type"))
|
||||||
print(" Turtle ID: " .. tostring(message.turtleID))
|
print(" Turtle ID: " .. tostring(message.turtleID))
|
||||||
else
|
|
||||||
print(" Message is not a table, it's: " .. type(message))
|
|
||||||
end
|
|
||||||
|
|
||||||
if channel == STATUS_CHANNEL and type(message) == "table" and message.type == "status" then
|
if message.type == "status" then
|
||||||
-- Status update from turtle
|
-- Status update from turtle
|
||||||
print("✓ Valid status from Turtle " .. (message.turtleID or "?"))
|
print("✓ Valid status from Turtle " .. (message.turtleID or "?"))
|
||||||
|
|
||||||
@@ -96,6 +95,13 @@ while true do
|
|||||||
else
|
else
|
||||||
print(" -> Failed to send to server")
|
print(" -> Failed to send to server")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
print(" Ignoring non-status message")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Ignore non-table messages (from other mods/systems)
|
||||||
|
-- Silently skip to avoid spam
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sleep(0.1) -- Small delay to prevent overwhelming the system
|
sleep(0.1) -- Small delay to prevent overwhelming the system
|
||||||
|
|||||||
Reference in New Issue
Block a user