Advertisement
Guest User

client test lua vic

a guest
Dec 11th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 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 = 25,
  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. rednet.broadcast("GetIDTurtleVic")
  23. local senderId, message = rednet.receive(Config.timeout)
  24. if message and string.find(message, "IDNEW") then
  25. args = {}
  26. for argument in message:gmatch("%w+") do table.insert(args, argument) end
  27. self.IDServer = senderId
  28. self.IDTurtle = args[2]
  29. end
  30. end
  31.  
  32. print("ID de turtle: ".. self.IDTurtle " asignada por el servidor: " .. self.IDServer)
  33.  
  34. print("Obtenint senyal GPS.....")
  35. self:getGPS()
  36. if self.PosActual == "ERROR" then
  37. return false
  38. end
  39.  
  40. print("Senyal GPS trobada, la posició actual és: " .. self.PosActual.x .. " x, ".. self.PosActual.y .. " y, " .. self.PosActual.z .. " z")
  41.  
  42.  
  43. self.Inicialitzat = true
  44. return true
  45. end
  46.  
  47. function Turtle:getGPS()
  48. local timeout = tonumber(Config.timeout)
  49. local vectorA = vector.new(gps.locate(timeout))
  50. if not vectorA.x then
  51. print(" /!\\ Error al intentar aconseguir la posició GPS /!\\ ")
  52. self.PosActual = "ERROR"
  53. else
  54. self.PosActual = vectorA
  55. end
  56. return true
  57. end
  58.  
  59. function Turtle:getID()
  60. self.IDTurtle = nil --TODO Implementar
  61. end
  62.  
  63. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement