Advertisement
Indie_Rogers

gps

Jun 29th, 2022 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. local clock = os.clock
  2. function sleep(n)
  3. local t0 = clock()
  4. while clock() - t0 <= n do end
  5. end
  6.  
  7. function getGPS()
  8. local f=fs.open("/data/homepos", "r")
  9. local tbl = textutils.unserialise (f.readAll())
  10. f.close()
  11.  
  12. local curx, cury, curz = gps.locate(5)
  13.  
  14. local distx = curx-tbl.x
  15. local disty = cury-tbl.y
  16. local distz = curz-tbl.z
  17.  
  18. local distsum=distx+disty+distz
  19.  
  20. local absdist=math.abs(distsum)
  21.  
  22. print ("I am "..math.floor(absdist+0.5).."m away from home")
  23. sleep(0.1)
  24. term.setCursorPos(1,1)
  25. term.clear()
  26. term.setCursorPos(1,1)
  27.  
  28. end
  29.  
  30. while true do
  31. getGPS()
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement