Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GPS Satellite Code
- local gpsDataFiles = { "x.data", "y.data", "z.data" }
- -- Create data files if they don't exist
- for _, filename in ipairs(gpsDataFiles) do
- if not fs.exists(filename) then
- local file = fs.open(filename, "w")
- file.writeLine("0") -- Initialize with 0
- file.close()
- end
- end
- -- Function to get coordinates from the user
- local function getCoordinates()
- term.write("Enter GPS Coordinates (x y z): ")
- local input = read()
- local x, y, z = input:match("(%S+)%s+(%S+)%s+(%S+)")
- return tonumber(x), tonumber(y), tonumber(z)
- end
- -- Function to broadcast GPS data
- local function broadcastGPS()
- local x, y, z = getCoordinates()
- -- Write coordinates to data files
- local files = { fs.open("x.data", "w"), fs.open("y.data", "w"), fs.open("z.data", "w") }
- files[1].writeLine(tostring(x))
- files[2].writeLine(tostring(y))
- files[3].writeLine(tostring(z))
- for _, file in ipairs(files) do
- file.close()
- end
- -- Broadcast to Doggy.net/gps (simulated)
- print("Broadcasting GPS data to Doggy.net/gps: (" .. x .. ", " .. y .. ", " .. z .. ")")
- end
- -- Main loop
- while true do
- broadcastGPS()
- sleep(5) -- Broadcast every 5 seconds
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement