Skip to content

Commit 1963d84

Browse files
committed
Fix desync in global checker
Can't do logic based on a local variable like that. Instead just run in on_init/on_configuration_changed. Resolves pyanodon/pybugreports#1315
1 parent 2e20738 commit 1963d84

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

lib/lib.lua

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,18 @@ if py.stage == "data" then
274274
}
275275
end
276276

277-
local data_message_sent = false
278-
local control_message_sent = false
279277
local control_globals_outside_of_events = false
280278
if py.stage == "control" then
281-
py.on_event(defines.events.on_tick, function(_)
282-
---@diagnostic disable-next-line: undefined-field
283-
if not data_message_sent and prototypes.mod_data["py-undocumented-globals"].get("exist") then
284-
game.print("[color=255,0,0]found references to undefined globals in data stage, check logs[/color]")
285-
data_message_sent = true
286-
end
287-
if not control_message_sent and control_globals_outside_of_events then
288-
game.print("[color=255,0,0]found references to undefined globals in control stage, check logs[/color]")
289-
control_message_sent = true
279+
py.on_event(py.events.on_init(), function(changes --[[@as ConfigurationChangedData --]])
280+
-- We only run if it's a new map or startup change
281+
if not changes or changes.new_version or changes.migration_applied or changes.mod_startup_settings_changed or table_size(changes.mod_changes) > 0 then
282+
---@diagnostic disable-next-line: undefined-field
283+
if prototypes.mod_data["py-undocumented-globals"].get("exist") then
284+
game.print("[color=255,0,0]found references to undefined globals in data stage, check logs[/color]")
285+
end
286+
if control_globals_outside_of_events then
287+
game.print("[color=255,0,0]found references to undefined globals in control stage, check logs[/color]")
288+
end
290289
end
291290
end)
292291
end

0 commit comments

Comments
 (0)