Design Discussion Persistance and Settings

Talk nerdy to us here.
Post Reply
User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Persistance and Settings

Post by JunJayMdM » November 21st, 2012, 1:15 am

Hi twallan, I was curious about how this thing is handled by the game, cos I noticed a strange behavior. Let me explain :

I use persistable settings in some of my mods and they work fine, they always persist when saving and reloading the game.
The exception is when a sim goes on Vacation, for the first time after installing one of my mods with persistable settings, all of the settings are there and persisted BUT if I change them, when going back home there will be the values stored before the sim departed.
After this, each world will keep a different set of persisted values.

Just to make sure I wasn't doing something wrong, I tested it with Master Controller and here's what happened :

1) Homeworld : I set "Allow more than 8 sims" to TRUE.

2) The Sim goes on Vacation and in that world I see "Allow more than 8 sims" to TRUE. Good, I set it to FALSE.

3) Back to Homeworld : I check the setting and its value is back to TRUE. The change made on Vacation didn't persist!

4) Again the Sim goes on Vacation : the setting is FALSE, it kept the change made during the last travel, while in the Homeworld the setting was TRUE.

I hope that was clear enough and that you could shed some light into this weird "issue", since it apparently affects your mods too.

Thanks :)

User avatar
twallan
Reactions:
Posts: 270
Joined: December 26th, 2011, 6:00 pm

Post by twallan » November 21st, 2012, 4:08 pm


If you don't clear your [PersistableStatic] elements during transition those values will be automatically used as the defaults in any town-file you load that does not contain that persisted field.

I do that intentionally in my mods, so when you travel to a brand new world you don't need to set up your settings again.

It also happens if you return to the Main Menu and start a new game, the options from the previous game you had loaded are applied as the defaults for your new town.

However, if you want that not to happen, simply clear the values during the OnWorldQuit() event. For instance, Buzzler has noted in the past that it is their preferred method to clear the settings during OnWorldQuit. :)

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » November 21st, 2012, 4:21 pm

For my settings I use a single PersistableStatic element, which is the instance of the Settings class (you do that in your mods).

Two questions though :

1) If I "null" the instance during OnWorldQuit(), which is something I do to reset them, will they be kept for saved Worlds? I assume they will, the save data should store them, everytime the mod is reloaded, the instance is null anyway (yes I answered myself while asking it, lol)

2) Is it possible to make them Global? Like, wherever you go, they still are the same, and if you change a setting on Vacation then it will stick when the Sim is back home?

User avatar
twallan
Reactions:
Posts: 270
Joined: December 26th, 2011, 6:00 pm

Post by twallan » November 21st, 2012, 4:57 pm


1) OnWorldQuit occurs after the data is saved to file, so setting the field to "null" at that point will not impact persistence into the save-file.

2) Sure, store your settings in two different static fields, one that is persistent, and one that is not.

When you change worlds, copy the information from the non-persistent static into the persistent field during your OnWorldLoadFinished() event. :)

User avatar
JunJayMdM
Reactions:
Posts: 262
Joined: April 2nd, 2012, 6:00 pm

Post by JunJayMdM » November 21st, 2012, 5:01 pm

1) Yeah I suspected that, I realized it after asking, plus I already did it and tested it. Works great ;)

2) lol, why didn't I think of that? I mean, I have one option to reset settings except a couple, where I store values, do the reset and reapply the stored values. That's so simple!

Thanks a lot for the explanation and the precious tips, I really appreciated it :)

Post Reply