There is no reason to check if a players GUI has been setup every single tick when this can simply be done once when the player connects as you're already doing in control.lua:1862, the gui_buttons() function does not actually seem to update the state of any GUI elements, it only seems to setup the required GUI elements then
finish.
Just checked: That call was there before I meddled with this mod. "check_state()" sounds important so I probably thought it would check the state of the vehicles. Not sure why it has been included there in the first place, but you're right: It doesn't seem to make much sense.
Perhaps I am not fully understanding, but what is the reason to destroy and totally recreate the GUI for every player in the server when only one single player joins? - this seems very strange.
Apparently you didn't read the comment above that:
--------------------------------------------------------------------------------------------
-- Reset GUI if a new player joins the game or a player returns (on_player_joined_game
-- works in multiplayer and singleplayer mode). (Pi-C)
script.on_event({defines.events.on_player_created, defines.events.on_player_joined_game}, function(event)
GCKI = GCKI or GCKI_installed()
check_state("init")
end)
You're right that it doesn't make much sense for multiplayer (MP) games. However, if I fire up Factorio and load a game in single player (SP) mode, on_player_joined_game will trigger as well. The thing is, all players will have to use the same configuration (same version of game and mods) -- but while nobody but the admin/host of a game in MP can add/remove mods or change global settings, "all players" IS the admin in SP games. Every time somebody loads the game in SP, some mod may have been added or removed; if that mod is GCKI, I need to rebuild the GUI for "everyone" (i.e. the only single player).
Thinking about it, it seems strange why I didn't do this in on_configuration_changed only, but it's almost a month ago since I made the last update and I can't really remember. However, I've found this comment to my own future self:
--------------------------------------------------------------------------------------------
-- This function will usually be called with just one argument (player). If there is a
-- second argument ("init"), it will force removal/rebuilding of the GUI. This is needed for
-- on_configuration_changed and on_player_joined_game to make sure the GUI will be up to
-- date if a mod has been added/removed or mod settings have changed.
local function gui_buttons(player, init)
I guess only acting in on_configuration_changed didn't work quite as expected. :-D
Also, I usually play SP. For testing, I've run MP locally, with two Factorio instances on the same computer. That's awfully slow already, and both players join only once per "game" session, so this extra call hardly mattered. However, I can see that it's probably different in a real MP game that goes on for hours, with players disconnecting/reconnecting frequently. A solution would be to separate the events for on_player_created and on_player_joined_game, and add a check for "not MP game" before calling check_state in on_player_joined_game.
Just some tips i guess :)
Thank you! If you happen to play real MP games, I'd be glad about more feedback (also regarding GCKI) -- there are things you just don't think about if you have no first-hand experience …