sshikamaru

factorio - Gestion nombre station train

Dec 7th, 2025
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.64 KB | None | 0 0
  1. -- Définir le nombre maximum de stations
  2. local MAX_STATIONS = 4
  3.  
  4. -- Lecture du signal d'entrée
  5. local c = red['signal-C'] or 0
  6.  
  7. -- Initialisation du compteur si inexistant
  8. var.counter = var.counter or 1
  9. var.last_c = var.last_c or c
  10.  
  11. -- Détection d'un départ de train
  12. if c < var.last_c then
  13.     -- Incrémenter le compteur
  14.     var.counter = var.counter + 1
  15.     if var.counter > MAX_STATIONS then
  16.         var.counter = 1
  17.     end
  18. end
  19.  
  20. -- Si aucune gare n'a de train, on remet le compteur à 1
  21. if c == 0 then
  22.     var.counter = 1
  23. end
  24.  
  25. -- Mise à jour de la dernière valeur de C
  26. var.last_c = c
  27.  
  28. -- Sortie
  29. out['signal-T'] = var.counter
Advertisement
Add Comment
Please, Sign In to add comment