Check save/load and selection rank
I would not be surprised if luaUI needs some handling to maintain selection rank state. There are numerous other tickets about luaUI things that are not remembered by save/load. What is even possible here, given that I assume players can launch each others save games?
Both LuaUI and unsynced LuaRules are completely dropped from the save state.
I assume players can launch each others save games?
I think you can also save a co-op game (or even a PvP lobpot), in which case there's multiple unsynced states that would need saving.
Hmm I had assumed as much. Yet by far the most common save/load will be of singleplayer people loading their own games. Perhaps the engine should have a save event for the unsynced states, to be able to put data in saves, to be retrieved with an event when the game loads.
The caveman gameside solution would be to do /luarules blabla with whatever data needs saving and a gadget would put that into rules params. Engine events sound good.
Technically we could generate a unique random number when the game starts, and chuck it in game rules params (for all I know we already do). Then widgets could store whatever they might want when they save into a table indexed by this unique ID, and load it when initialised when the game loads with a matching ID. To support multiple saves at different points in the same game, we'd append the frame to the table ID.
This only depends on widgets getting some form of event when the game saves. They surely already initialise when the game loads. But it would also be a horrible hack that clutters up luaUI configs, and which would be lost when people delete their luaUI configs or try to transfer saves to a new PC. So the non-hacky engine feature would be to make such a table available to luaUI.