Advertisement
Mordrack

Untitled

Jun 8th, 2013
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. local nbPuit = 0
  2. local nbPuitsTotal = 0
  3. local profondeur = 0
  4. local message = "attente"
  5. mon = peripheral.wrap("right")
  6.  
  7. function split(str,pat)
  8.  
  9. local t = {}
  10. local fpat = "(.-)" .. pat
  11. local last_end = 1
  12. local s, e, cap = str:find(fpat, 1)
  13. while s do
  14. if s ~= 1 or cap ~= "" then
  15. table.insert(t,cap)
  16. end
  17. last_end = e+1
  18. s, e, cap = str:find(fpat, last_end)
  19. end
  20. if last_end <= #str then
  21. cap = str:sub(last_end)
  22. table.insert(t, cap)
  23. end
  24. return t
  25. end
  26.  
  27.  
  28. function affiche_etat()
  29.  
  30. mon.clear()
  31. mon.setCursorPos(4,4)
  32. if message == "attente" then
  33. mon.write("En attente de la tortue...")
  34. elseif message == "encours" then
  35. mon.write("Avancement du minage : "..nbPuit.."/"..nbPuitsTotal)
  36. mon.setCursorPos(4,6)
  37.  
  38. if profondeur == 0 then
  39. mon.write("Profondeur : "..profondeur)
  40. else
  41. mon.write("Profondeur : -"..profondeur)
  42. end
  43. elseif message == "retour" then
  44. mon.write("Minage fini, retour au point de depart...")
  45. elseif message == "fin" then
  46. mon.write("Minage fini !")
  47. end
  48.  
  49. end
  50.  
  51.  
  52.  
  53. rednet.open("left")
  54. affiche_etat()
  55.  
  56. while true do
  57. event, id, text = os.pullEvent()
  58. if event == "rednet_message" then
  59. local tab = split(text,":")
  60. if tab[1] == "etat" then message = tab[2] end
  61. if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tab[2] end
  62. if tab[1] == "nbPuits" then nbPuit = tab[2] end
  63. if tab[1] == "profondeur" then profondeur = tab[2] end
  64. affiche_etat()
  65. end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement