diff --git a/control.lua b/control.lua index 28e6792..fc224a0 100644 --- a/control.lua +++ b/control.lua @@ -44,10 +44,6 @@ end script.on_init(evogui.mod_init) script.on_configuration_changed(evogui.mod_update) -script.on_load(function() - local status, err = pcall(RemoteSensor.initialize) - if err then evogui.log({"err_generic", "on_load", err}) end -end) script.on_event(defines.events.on_player_created, function(event) local status, err = pcall(evogui.new_player, event) @@ -55,8 +51,10 @@ script.on_event(defines.events.on_player_created, function(event) end) script.on_event(defines.events.on_tick, function(event) + local status, err = pcall(RemoteSensor.initialize) + if err then evogui.log({"err_generic", "on_tick:remote_initialize", err}) end local status, err = pcall(evogui.update_gui, event) - if err then evogui.log({"err_generic", "on_tick", err}) end + if err then evogui.log({"err_generic", "on_tick:update_gui", err}) end end) script.on_event(defines.events.on_gui_click, function(event) diff --git a/value_sensors/remote_sensor.lua b/value_sensors/remote_sensor.lua index 64eb87f..8ab6657 100644 --- a/value_sensors/remote_sensor.lua +++ b/value_sensors/remote_sensor.lua @@ -30,7 +30,11 @@ function RemoteSensor.get_by_name(name) return ValueSensor.get_by_name("remote_sensor_" .. name) end +local remote_initialized = false + function RemoteSensor.initialize() + if remote_initialized then return end + -- Initialize any remote sensors that were previously saved if global.remote_sensors then for _, sensor_data in pairs(global.remote_sensors) do @@ -39,6 +43,8 @@ function RemoteSensor.initialize() end end end + + remote_initialized = true end return RemoteSensor