Advertisement
DOGGYWOOF

GPS satalite

Oct 7th, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. -- GPS Satellite Code
  2.  
  3. local gpsDataFiles = { "x.data", "y.data", "z.data" }
  4.  
  5. -- Create data files if they don't exist
  6. for _, filename in ipairs(gpsDataFiles) do
  7. if not fs.exists(filename) then
  8. local file = fs.open(filename, "w")
  9. file.writeLine("0") -- Initialize with 0
  10. file.close()
  11. end
  12. end
  13.  
  14. -- Function to get coordinates from the user
  15. local function getCoordinates()
  16. term.write("Enter GPS Coordinates (x y z): ")
  17. local input = read()
  18. local x, y, z = input:match("(%S+)%s+(%S+)%s+(%S+)")
  19. return tonumber(x), tonumber(y), tonumber(z)
  20. end
  21.  
  22. -- Function to broadcast GPS data
  23. local function broadcastGPS()
  24. local x, y, z = getCoordinates()
  25.  
  26. -- Write coordinates to data files
  27. local files = { fs.open("x.data", "w"), fs.open("y.data", "w"), fs.open("z.data", "w") }
  28. files[1].writeLine(tostring(x))
  29. files[2].writeLine(tostring(y))
  30. files[3].writeLine(tostring(z))
  31.  
  32. for _, file in ipairs(files) do
  33. file.close()
  34. end
  35.  
  36. -- Broadcast to Doggy.net/gps (simulated)
  37. print("Broadcasting GPS data to Doggy.net/gps: (" .. x .. ", " .. y .. ", " .. z .. ")")
  38. end
  39.  
  40. -- Main loop
  41. while true do
  42. broadcastGPS()
  43. sleep(5) -- Broadcast every 5 seconds
  44. end
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement