Advertisement
Guest User

test lua vic 2

a guest
Dec 11th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. Turtle = {
  2. IDTurtle = nil,
  3. IDServer = nil,
  4. Inici = nil,
  5. PosActual = nil,
  6. Inicialitzat = false
  7. }
  8.  
  9. Config = {
  10. timeout = 5,
  11. serverName = "ServidorTurtlesVic"
  12.  
  13. }
  14.  
  15. function main()
  16. Turtle:inicialitzar()
  17. end
  18.  
  19. function Turtle:inicialitzar()
  20. rednet.open("right")
  21. while ( not(self.IDServer)) do
  22. local senderId, message = rednet.receive(5)
  23. if string.find(message, "IDNEW") then
  24. args = {}
  25. for k, argument in string.gmatch(message, "[^%s]+") do
  26. args[k] = argument
  27. end
  28. self.IDServer = args[2]
  29. end
  30. end
  31.  
  32. self:getGPS()
  33. if self.PosActual == "ERROR" then
  34. return false
  35. end
  36.  
  37.  
  38. self.Inicialitzat = true
  39. return true
  40. end
  41.  
  42. function Turtle:getGPS()
  43. local timeout = tonumber(Config.timeout)
  44. local vectorA = vector.new(gps.locate(timeout))
  45. if not vectorA.x then
  46. print(" /!\\ Error al intentar aconseguir la posició GPS /!\\ ")
  47. self.PosActual = "ERROR"
  48. else
  49. self.PosActual = vectorA
  50. end
  51. return true
  52. end
  53.  
  54. function Turtle:getID()
  55. self.IDTurtle = nil --TODO Implementar
  56. end
  57.  
  58. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement