feat: Add error handling for turtle startup script and improve GPS retry logic
This commit is contained in:
@@ -34,8 +34,21 @@ if response then
|
|||||||
print("Starting turtle program...")
|
print("Starting turtle program...")
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
||||||
-- Run the script
|
-- Run the script with error handling
|
||||||
|
local success, error = pcall(function()
|
||||||
shell.run(SCRIPT_NAME)
|
shell.run(SCRIPT_NAME)
|
||||||
|
end)
|
||||||
|
|
||||||
|
if not success then
|
||||||
|
print("")
|
||||||
|
print("========================================")
|
||||||
|
print(" ERROR OCCURRED!")
|
||||||
|
print("========================================")
|
||||||
|
print(error)
|
||||||
|
print("")
|
||||||
|
print("Press any key to see error details...")
|
||||||
|
os.pullEvent("key")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
print("✗ Download failed!")
|
print("✗ Download failed!")
|
||||||
print("Please check:")
|
print("Please check:")
|
||||||
|
|||||||
@@ -965,13 +965,18 @@ print("Turtle " .. os.getComputerID() .. " is online!")
|
|||||||
parallel.waitForAny(
|
parallel.waitForAny(
|
||||||
function()
|
function()
|
||||||
-- GPS retry loop for turtles without initial position
|
-- GPS retry loop for turtles without initial position
|
||||||
while not state.position do
|
while true do
|
||||||
|
if not state.position then
|
||||||
sleep(10) -- Try every 10 seconds
|
sleep(10) -- Try every 10 seconds
|
||||||
print("Retrying GPS...")
|
print("Retrying GPS...")
|
||||||
if updatePosition() then
|
if updatePosition() then
|
||||||
print("✅ GPS acquired! Position:", textutils.serialize(state.position))
|
print("✅ GPS acquired! Position:", textutils.serialize(state.position))
|
||||||
broadcastStatus() -- Send updated position immediately
|
broadcastStatus() -- Send updated position immediately
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
-- Once we have position, just sleep to keep this thread alive
|
||||||
|
sleep(30)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user