Default not working correctly?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Message
Author
Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Default not working correctly?

#1 Post by Onishion »

I've been getting feedback on an issue and I'm not sure what's causing it. My understanding is that when you use "default Variable", then it will initialize that variable even in old saved games, and it almost has to work that way usually or most of my game updates would end up super buggy.

But recently, a few players have reported that certain variables that might be new since their last saved game have not been working right when they load their saves, it throws back "name 'Variable' is not defined" blue screen errors, across a few different variables, usually when those variables are used as conditionals in menu statements, such as ""go to there" if Variable:". I'm using Renpy 6.99.4, so if it's something that's been updated since then I might upgrade.

The thing is, it has to work at least some of the time, because I add plenty of new variables each update and for the most part, most players are not having issues with that, it's just a few people with a few variables where they don't seem to be "defaulting" properly.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Default not working correctly?

#2 Post by xela »

Never heard of this, proper test case is needed...
Like what we're doing? Support us at:
Image

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Default not working correctly?

#3 Post by Onishion »

Yeah, I'm not really sure what's causing it, and I'm getting the reports in second hand. All the variables in question are initialized using a long init -1: block, default Variable = "whatever", and in most cases this seems to work fine, if it didn't then the game would be completely unplayable for anyone due to "variable not defined" errors, but only some people are getting them some of the time, and only when loading from old saves. Is there anything that could cause a variable to "de-initialize," or for a default statement to get skipped somehow when loading a saved game?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Default not working correctly?

#4 Post by xela »

No idea... my guess would be no but there always could be some weird combinations of code/events.
Like what we're doing? Support us at:
Image

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Default not working correctly?

#5 Post by nyaatrap »

Code: Select all

label after_load:
    if "new" not in globals().keys():
        $new=0
    return
It's not radical solution, but it'll update save data manually.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Default not working correctly?

#6 Post by Onishion »

Interesting, would it be too much trouble to walk me through how that works? Is "after_load" a special label that plays after a save is loaded up, or would I have to put it someplace specific? Is globals().keys() all the "know" variables? And would I need to make a unique if statement for each variable that might cause issues?

I actually have added a mechanism to update old saves to new paradigms, but it's somewhat primitive and a better way would be nice. Something that would load after each save is loaded up would be better than what I've got.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Default not working correctly?

#7 Post by nyaatrap »

https://www.renpy.org/doc/html/label.ht ... ial-labels

after_load is called every time any save data is loaded, even shift+R.
globals().key() returns all global variables as strings. If "X" is not listed in it, then add variable X.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Default not working correctly?

#8 Post by Onishion »

Hmm. Very interesting. So I would need to add one of those for any variable that's been added to the game since earlier versions, but that might be worth it. It would only need to load once each time a save is loaded, at least. I could also combine that with my existing version-checking element to streamline it a bit. Thanks, this could come in quite handy. I do still wish I knew what was going on with default though.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Default not working correctly?

#9 Post by xela »

Default prolly does the same thing... Test case is needed, save file from the game where this occurred so you could track down the problem. Nothing like this has ever been reported and default seems to be working in normal testcases.
Like what we're doing? Support us at:
Image

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Default not working correctly?

#10 Post by Onishion »

Ok, I tracked down an older save file, and it does cause hellacious issues. Default doesn't seem to be working as it's meant to, it's not initializing variables that were created after the save file was formed. The save file does really weird stuff too, like it shows up and works fine for a bit, but then if I try to save it again from that old save, and load that, or if I try to reload the game while in that save file, it crashes because it can't find some sprite variables I created after that save. Basically if I load up the save, and open the variable viewer, there are a TON of variables missing from it that should be defaulted.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Default not working correctly?

#11 Post by xela »

The amount of variable shouldn't matter, if you can understand the issue enough to narrow it down so it could be used in a dummy project to create a situation with an error, maybe it can be fixed for everyone (over the whole engine).

I am not using default a lot, my (main) project is very old and it'll be a pain to rewrite loafing routines just to for that I've tested it a bit to understand it better and it passed all the cr@p I tried killing it with ;)
Like what we're doing? Support us at:
Image

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Default not working correctly?

#12 Post by Onishion »

Hmm, I might try to figure something out, I'm just not exactly sure where to start. I mean, the problem is with older saves of my game not loading up in the latest version with the variables it should. I mean they define all right for people loading a new game, so they're obviously getting read and put into action on a new game load, they just aren't being considered at all by an older loaded save game, and I thought that was the whole point of using default rather than just using "$ Variable = 0" in the init block. I'll play with it some more later. I tried loading the game with the defaulted variables in an init -1 block like I had it, and also in an init: block, and without declaring an init at all, and in all three it would load normally fresh, but fail to initialize new variables into the older save. Maybe it's a problem with 6.99.4 that got fixed in later Renpy versions.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Default not working correctly?

#13 Post by nyaatrap »

I don't know it's related or not, but I figured out if I 'del' variable in a game, I never add the same variable by default. As if 'del variable' is recorded in save data.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Default not working correctly?

#14 Post by Onishion »

You mean that if you use default on a variable, and then later you "del" it, then it doesn't come back due to default? That may play at least part of a role in what I'm seeing here, since some of the relevant variables get a "del [:]" list clearing process at various points.

User avatar
Zet
Regular
Posts: 26
Joined: Wed Feb 13, 2013 12:48 am
Completed: Max's Big Bust
Organization: Lached Up Games
Contact:

Re: Default not working correctly?

#15 Post by Zet »

Holy crap I'm not crazy! I've been having this problem a LOT recently, it wasn't much of an issue before but I've been having major save game compatibility errors with my latest game update, and everything was working fine before.
Check out Max's Big Bust on Steam - http://store.steampowered.com/app/416360

Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot]