Recently I've started working on a mod for LTN. It is supposed to become a GUI that displays stats about the train network. A bit like LTN content reader, but with more info and as a UI instead of an entity. The basics are working, but I ran into a small problem. There are two events transmitting data and I need both sets to process them. Which lead me to this construct:
Code: Select all
local function parse_new_data()
global.new_stops, global.new_dd = false, false
-- do stuff with global.raw and store output in global.output
end
local function on_stops_updated(event)
global.new_stops = true
global.raw.data_stops = event.data
if global.new_disp then
parse_new_data()
end
end
local function on_dispatcher_updated(event)
global.new_disp = true
global.raw.data_disp = event.data
if global.new_stops then
parse_new_data()
end
end
script.on_event(remote.call("logistic-train-network", "get_on_stops_updated_event"), ltn_parser.on_stops_updated)
script.on_event(remote.call("logistic-train-network", "get_on_dispatcher_updated_event"), ltn_parser.on_dispatcher_updated)