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...")
|
||||
sleep(1)
|
||||
|
||||
-- Run the script
|
||||
shell.run(SCRIPT_NAME)
|
||||
-- Run the script with error handling
|
||||
local success, error = pcall(function()
|
||||
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
|
||||
print("✗ Download failed!")
|
||||
print("Please check:")
|
||||
|
||||
17
turtle.lua
17
turtle.lua
@@ -965,12 +965,17 @@ print("Turtle " .. os.getComputerID() .. " is online!")
|
||||
parallel.waitForAny(
|
||||
function()
|
||||
-- GPS retry loop for turtles without initial position
|
||||
while not state.position do
|
||||
sleep(10) -- Try every 10 seconds
|
||||
print("Retrying GPS...")
|
||||
if updatePosition() then
|
||||
print("✅ GPS acquired! Position:", textutils.serialize(state.position))
|
||||
broadcastStatus() -- Send updated position immediately
|
||||
while true do
|
||||
if not state.position then
|
||||
sleep(10) -- Try every 10 seconds
|
||||
print("Retrying GPS...")
|
||||
if updatePosition() then
|
||||
print("✅ GPS acquired! Position:", textutils.serialize(state.position))
|
||||
broadcastStatus() -- Send updated position immediately
|
||||
end
|
||||
else
|
||||
-- Once we have position, just sleep to keep this thread alive
|
||||
sleep(30)
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user