Part of a mod I'm working on is keeping track of the nesting level of opened GUIs. The principle of the code looks like this:
on_gui_opened: ++gui_open_counter;
on_gui_closed: --gui_open_counter;
The code works, however if I open a chest and then mine it, the GUI disappears (as it should) but the on_gui_closed event doesn't fire. This happens if my mod is the only mod active.
The same also applies to the FNEI GUIs: If those are opened, the on_gui_opened event fires but on close, the on_gui_closed event don't get fired - this may be a bug in the mod, it may be a different bug in factorio but I guess, it will be the same underlying problem, that's why I mention it here.
The bug is 100% reproducibly.
[1.1.110]Event on_gui_closed does not fire if GUI is closed as a side-effect (e.g. an opened chest is mined)
Re: [1.1.110]Event on_gui_closed does not fire if GUI is closed as a side-effect (e.g. an opened chest is mined)
control.lua that demonstrates this bug:
Code: Select all
if global.bug_115401 == nil
then
global.bug_115401 = {}
global.bug_115401.open_gui_counter = 0
end
function update_gui(player)
if not global.bug_115401.gui
then
global.bug_115401.gui = player.gui.left.add{type="frame", name="bug_115401", direction="horizontal"}
end
global.bug_115401.gui.caption = "open_gui_counter = " .. global.bug_115401.open_gui_counter
end
script.on_event(defines.events.on_gui_opened, function(event)
local player = game.players[event.player_index]
global.bug_115401.open_gui_counter = global.bug_115401.open_gui_counter + 1
update_gui(player)
end)
script.on_event(defines.events.on_gui_closed, function(event)
local player = game.players[event.player_index]
global.bug_115401.open_gui_counter = global.bug_115401.open_gui_counter - 1
update_gui(player)
end)
Re: [1.1.110]Event on_gui_closed does not fire if GUI is closed as a side-effect (e.g. an opened chest is mined)
Thanks for the report however that is working correctly. Because the entity is destroyed the event can not fire with the now invalid entity and so no event happens. There are also other cases where the event won’t fire such as the player dying.
If you want to get ahold of me I'm almost always on Discord.
Re: [1.1.110]Event on_gui_closed does not fire if GUI is closed as a side-effect (e.g. an opened chest is mined)
Ok, since there is no other event like on_gui_disappeared or such, is there any way at all to figure out, that the gui that was visible before is now not visible any longer?
If not, can we please get a new event on_gui_disappeared which fires exactly once for each gui that disappears for whatever reason as long as it called on_gui_opened before?
If not, can we please get a new event on_gui_disappeared which fires exactly once for each gui that disappears for whatever reason as long as it called on_gui_opened before?
Re: [1.1.110]Event on_gui_closed does not fire if GUI is closed as a side-effect (e.g. an opened chest is mined)
There is no other event. But you can simply read the current opened GUI for a given player to see what they have open - if anything.
If you want to get ahold of me I'm almost always on Discord.