From af2d120baab23527566d201e19ef57d88bf069d8 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Fri, 20 Feb 2026 00:32:40 -0500 Subject: [PATCH] feat: Add error handling for turtle startup script and improve GPS retry logic --- startup_turtle.lua | 17 +++++++++++++++-- turtle.lua | 17 +++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/startup_turtle.lua b/startup_turtle.lua index 1e97d96..c47f8a2 100644 --- a/startup_turtle.lua +++ b/startup_turtle.lua @@ -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:") diff --git a/turtle.lua b/turtle.lua index 04c42ed..db32c7d 100644 --- a/turtle.lua +++ b/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,