Track Organiser

How to write a script in track oraniser to print count of buses and use loop to acess buses

A Lua script?

local cnt = 0
for route in Session:get_routes ():iter () do -- for every track/bus
 -- see if it a track
 if route:to_track():isnil () then
    -- not a track, so this is a bus
    if not route:is_master() and not route:is_monitor() then -- skip the master bus
      cnt = cnt + 1
    end
  end
end
print("Bus count:", cnt) 

Ya i was running a similar script but it is giving error as referencing nil value