Advertisement
DOGGYWOOF

Untitled

Aug 6th, 2024 (edited)
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. -- startup
  2.  
  3. -- Function to display a full-screen error message
  4. function displayError(message)
  5. term.clear() -- Clear the screen
  6. term.setCursorPos(1, 1) -- Set the cursor to the top-left corner
  7. local width, height = term.getSize()
  8. local xPos = math.floor((width - string.len(message)) / 2) -- Center the text horizontally
  9. local yPos = math.floor(height / 2) -- Center the text vertically
  10. term.setCursorPos(xPos, yPos)
  11. term.write(message)
  12. sleep(3) -- Display the message for 3 seconds
  13. term.clear() -- Clear the screen after showing the error
  14. end
  15.  
  16. -- Function to run a program with error handling
  17. function runWithErrorHandling(programName)
  18. local success, err = pcall(function()
  19. shell.run(programName)
  20. end)
  21.  
  22. if not success then
  23. displayError("Error: " .. err)
  24. end
  25. end
  26.  
  27. -- Execute the program with error handling
  28. runWithErrorHandling("program.lua")
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement