How do I destroy a GUI on load after a mod update?

Place to get help with not working mods / modding interface.
Post Reply
JasonC
Filter Inserter
Filter Inserter
Posts: 363
Joined: Tue Mar 22, 2016 3:05 am
Contact:

How do I destroy a GUI on load after a mod update?

Post by JasonC »

I have a mod that creates a GUI with a bunch of buttons on it. However, in a newer version, I changed the buttons to checkboxes. This means the new styles are checkbox_styles, not button_styles.

The problem is that when the game is saved it saves GUIs in the save file. So if the user saved the game with the GUI open, when they load the game after updating the module, the game tries to create buttons, but the new styles are for checkboxes. Therefore the new styles are incompatible, the game pops up an error dialog and exits completely, and the user has no way to load their game unless they downgrade the module, open the game, close the GUI, save it, then upgrade. Which... yeah.

So my question is, how can I destroy the GUI before it loads, so that if I make a module update that makes style changes incompatible with the old GUI, the saved old GUI doesn't crash the game?

I can't do it in on_init because that function isn't called at the right times.

I can't do it in on_load because there's no access to 'game' there, and the GUI is stored with game.player.

I can't do it in on_configuration_changed because that happens after the GUI is loaded from the save, so it doesn't solve the problem.

The only option I can really think of is to keep the old styles around for compatibility and give the new styles different names, but I really don't like the idea of lugging these old styles around for all eternity just to support users who may be updating from an older incompatible version who saved the game with the GUI open. (The other problem with that is my styles are actually programatically generated based on the game's item prototypes, since this is the only way to put game icons on GUI's, really, so if an item is removed in the future I can't even guarantee that all the old compatibility styles will stick around.)

How can I stop this from happening?
Last edited by JasonC on Tue Apr 19, 2016 11:29 pm, edited 1 time in total.
Took a break from 0.12.29 to 0.17.79. I never know what's happening.
Gates are broken for trains. | The people demand a better chain signal! | Disabled inserters are a lie! (see also)


JasonC
Filter Inserter
Filter Inserter
Posts: 363
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Re: How do I destroy a GUI on load after a mod update?

Post by JasonC »

Supercheese wrote:Migration script maybe?
A solid suggestion but nope, same issue as on_configuration_changed.

In fact it's a bit of a catch-22... the only way to destroy() the GUI is if the GUI has been loaded into game.player. But it can't be loaded because of the style incompatibilities. So the more I think about it the more I think you're pretty much just totally hosed if you make your styles incompatible in a mod update where the GUI existed when the user saved.
Took a break from 0.12.29 to 0.17.79. I never know what's happening.
Gates are broken for trains. | The people demand a better chain signal! | Disabled inserters are a lie! (see also)

JasonC
Filter Inserter
Filter Inserter
Posts: 363
Joined: Tue Mar 22, 2016 3:05 am
Contact:

Re: How do I destroy a GUI on load after a mod update?

Post by JasonC »

Ok I found a workaround. The way you have to do it is give the new styles different names from the old ones, but remove the old ones completely. Do not re-use their style names.

When the game loads a GUI with incompatible styles it errors and exits, but when it loads a GUI with non-existant styles, it simply doesn't draw the objects properly. This isn't 100% ideal but at least it lets the save be loaded, then you can destroy the GUI however you want (like in on_configuration_changed or just give the user instructions that they have to do it if you're lazy) and play can continue.
Took a break from 0.12.29 to 0.17.79. I never know what's happening.
Gates are broken for trains. | The people demand a better chain signal! | Disabled inserters are a lie! (see also)

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7328
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: How do I destroy a GUI on load after a mod update?

Post by bobingabout »

I was going to sugest using the on_configuration_changed to simply delete any active GUIs, but if you're saying the new GUI is completely incompatable with the old one to the point the game crashs, that's a different story. I'm happy to hear though that you've found a workable solution.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Modding help”