Advertisement
DOGGYWOOF

Locator

Oct 7th, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. -- GPS Locator Code
  2.  
  3. local gpsDataFiles = { "x.data", "y.data", "z.data" }
  4.  
  5. -- Function to read GPS data from files
  6. local function readGPSData()
  7. local coordinates = {}
  8. for _, filename in ipairs(gpsDataFiles) do
  9. if fs.exists(filename) then
  10. local file = fs.open(filename, "r")
  11. table.insert(coordinates, tonumber(file.readLine()))
  12. file.close()
  13. else
  14. print("GPS data file " .. filename .. " does not exist.")
  15. return nil
  16. end
  17. end
  18. return coordinates
  19. end
  20.  
  21. -- Function to display GPS coordinates
  22. local function displayGPS()
  23. local coordinates = readGPSData()
  24. if coordinates then
  25. print("Current GPS Coordinates: (X: " .. coordinates[1] .. ", Y: " .. coordinates[2] .. ", Z: " .. coordinates[3] .. ")")
  26. end
  27. end
  28.  
  29. -- Main loop
  30. while true do
  31. displayGPS()
  32. sleep(5) -- Check GPS data every 5 seconds
  33. end
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement