Advertisement
Fusion1227

TrainSignalSystem API

Oct 26th, 2023 (edited)
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. ----/ TrainSignalSystem class /---------------------------------------------
  2.  
  3.  
  4. local instances = {}
  5.  
  6.  
  7. --/ constructors /--
  8.  
  9.  
  10. function new(id1, id2, id3)
  11.     local self = {}
  12.     self.onSensorId = id1
  13.     self.offSensorId = id2
  14.     self.signalId = id3
  15.     self.isOn = false
  16.     return self
  17. end
  18.  
  19.  
  20. --/ functions /--
  21.  
  22.  
  23. function findFromComputerId(id)
  24.     for _, tss in pairs(instances) do
  25.         if tss.onSensorId == id or tss.offSensorId == id or tss.signalId == id then
  26.             return tss
  27.         end
  28.     end
  29. end
  30.  
  31.  
  32. ----/ linked computer ids /---------------------------------------------
  33.  
  34.  
  35. --[[  
  36.     In each array,
  37.     the first id is the computer linked to the activating sensor,
  38.     the second id is the computer linked to the deactivating sensor,
  39.     and the third id is the computer linked to the signal light
  40. ]]
  41.  
  42. local linkedIds = {
  43.     {120, 114, 113},
  44. }
  45.  
  46.  
  47. ----/ make systems from linked ids /---------------------------------------------
  48.  
  49.  
  50. for _, list in pairs(linkedIds) do
  51.     local trainSignalSystem = new(unpack(list))
  52.     table.insert(instances, trainSignalSystem)
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement