fix: Refactor message handling to improve status updates and server communication
This commit is contained in:
@@ -60,16 +60,15 @@ end
|
||||
while true do
|
||||
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)
|
||||
|
||||
if type(message) == "table" then
|
||||
print(" Message type: " .. (message.type or "no type"))
|
||||
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
|
||||
print("✓ Valid status from Turtle " .. (message.turtleID or "?"))
|
||||
|
||||
@@ -96,6 +95,13 @@ while true do
|
||||
else
|
||||
print(" -> Failed to send to server")
|
||||
end
|
||||
else
|
||||
print(" Ignoring non-status message")
|
||||
end
|
||||
else
|
||||
-- Ignore non-table messages (from other mods/systems)
|
||||
-- Silently skip to avoid spam
|
||||
end
|
||||
end
|
||||
|
||||
sleep(0.1) -- Small delay to prevent overwhelming the system
|
||||
|
||||
Reference in New Issue
Block a user