Skip to content

Commit

Permalink
Remove on_load function.
Browse files Browse the repository at this point in the history
Mutating global.* in on_load is a bad idea -- and it was happening,
through some misdirection. Let's avoid that, shall we?
  • Loading branch information
narc0tiq committed Jul 3, 2016
1 parent 9a8291a commit bd376e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 3 additions & 5 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,17 @@ 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)
if err then evogui.log({"err_generic", "on_player_created", err}) end
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)
Expand Down
6 changes: 6 additions & 0 deletions value_sensors/remote_sensor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,6 +43,8 @@ function RemoteSensor.initialize()
end
end
end

remote_initialized = true
end

return RemoteSensor

0 comments on commit bd376e8

Please sign in to comment.