[1.1.61] Switch raises on_gui_click twice
Posted: Sat Jul 23, 2022 1:19 pm
Problem: On_gui_click event fires twice when a switch is toggled.
Expected: Event only fires once.
To recreate:
* Run this command to create a gui element and hook into the event:
* Click the toggle in the center of the screen.
* Observe results:
1
2
Expected:
1
I suspect this wasn't noticed because most people interacting with this were listening to the toggle event which works fine, but for most use cases this event should work as well.
Expected: Event only fires once.
To recreate:
* Run this command to create a gui element and hook into the event:
Code: Select all
/c global.count = 0; game.player.gui.center.add{type="switch", name="bug"}; script.on_event(defines.events.on_gui_click, function() global.count = global.count +1 game.print(global.count) end)
* Observe results:
1
2
Expected:
1
I suspect this wasn't noticed because most people interacting with this were listening to the toggle event which works fine, but for most use cases this event should work as well.