help! values aren't preserving
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.
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.
help! values aren't preserving
I have a game where experience points go up sequentially. I tested it and have $mp.xp for the experience points. When I get a few xp, save, exit, and then load the game, the xp count resets to 0!
What am I doing wrong? Everything works as long as I stay in the same session, but once I quit and load my progress, it's all back to 0!!
Any help would be appreciated...
What am I doing wrong? Everything works as long as I stay in the same session, but once I quit and load my progress, it's all back to 0!!
Any help would be appreciated...
Re: help! values aren't preserving
Upon further testing I'm guessing that multipersistent variables don't really preserve like normal variables. I tried making the variable non-mp and it did preserve the correct numbering.
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: help! values aren't preserving
You need to run
To save multipersistent data to disk.
Code: Select all
$ mp.save()
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: help! values aren't preserving
Tried it but no dice... I must not know what I'm doing.
$mp.xp+=1
$mp.save()
show screen stats1
I also put the save after "show screen stats" but it still resets to 0 on load.
Bear in mind that I don't really know what I'm doing beyond simple jump and call statements.
$mp.xp+=1
$mp.save()
show screen stats1
I also put the save after "show screen stats" but it still resets to 0 on load.
Bear in mind that I don't really know what I'm doing beyond simple jump and call statements.
Re: help! values aren't preserving
I guess I should just be using the $mp.save() for persistence of data from one game to another. That does work. For persistence of variable values within one game, I'll stick with regular variables.
Does that make sense?
Does that make sense?
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: help! values aren't preserving
Well, what are you trying to use here. There's three levels of saving Ren'Py supports:
- Normal variables are specific to a single session of a game, including saves and loads of that session.
- Persistent variables are specific to a single project.
- Multipersistent varables are shared between projects.
From what you describe, it seems like you might want a persistent variable. It's hard to tell.
- Normal variables are specific to a single session of a game, including saves and loads of that session.
- Persistent variables are specific to a single project.
- Multipersistent varables are shared between projects.
From what you describe, it seems like you might want a persistent variable. It's hard to tell.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: help! values aren't preserving
Hmm... I admit I don't know about persistent variables.
I'm interested in normal variables but also in making those normal variables persistent when the user has completed the game. Upon opening another project, a completely different game/sequel, those normal variables will have multi-persisted.
I thought that I could just put "mp." in front of all my variables and that would do the trick, but I think I oversimplified it.
I'm interested in normal variables but also in making those normal variables persistent when the user has completed the game. Upon opening another project, a completely different game/sequel, those normal variables will have multi-persisted.
I thought that I could just put "mp." in front of all my variables and that would do the trick, but I think I oversimplified it.
Re: help! values aren't preserving
To elaborate: I want a character's experience points to accumulate throughout a game, and then carry over to the next game. If I use $mp.xp, the xp value does not save in between the time I save and then load a game. A normal variable like $xp does the trick.
So I think if I want the xp to carry over, I use $xp throughout the game and then associate it with $mp.xp at the end of the game so that it carries over to another project.
If anyone can confirm this is or isn't a terrible idea, please let me know.
So I think if I want the xp to carry over, I use $xp throughout the game and then associate it with $mp.xp at the end of the game so that it carries over to another project.
If anyone can confirm this is or isn't a terrible idea, please let me know.
- Aleema
- Lemma-Class Veteran
- Posts: 2677
- Joined: Fri May 23, 2008 2:11 pm
- Organization: happyB
- Tumblr: happybackwards
- Contact:
Re: help! values aren't preserving
How are you initializing the variable?
Re: help! values aren't preserving
I'm just putting the variables in like
$mp.xp=0
$mp.xpmax=200
Along with other regular variables, in the same way.
$mp.xp=0
$mp.xpmax=200
Along with other regular variables, in the same way.
- Aleema
- Lemma-Class Veteran
- Posts: 2677
- Joined: Fri May 23, 2008 2:11 pm
- Organization: happyB
- Tumblr: happybackwards
- Contact:
Re: help! values aren't preserving
Well, in order for persistent variables to work, you need to make sure they're only initialized once. For instance, this is how you would initialize a persistent variable:
Only if nothing is in your variable, will it set itself to False. It appears that you didn't do something like this, so every time Ren'Py inits (which is every instance), it will go through and see that it needs to be 0 again.
Also, where you initialize is important, I've found. Make sure all regular variables are initialized after the Start label or they won't be saved with that particular playthrough. *found out the hard way*
Code: Select all
if persistent.seen_opening is None:
$ persistent.seen_opening = False
Also, where you initialize is important, I've found. Make sure all regular variables are initialized after the Start label or they won't be saved with that particular playthrough. *found out the hard way*
Re: help! values aren't preserving
Hmmm... I declare regular variables before Start and they seem to save/load normally?
As for something like $mp.xp... do you mean I would declare $mp.xp=0 before "Start" and then after "Start" do something like
if mp.xp = 0:
$ mp.xp =
I don't even know what I would put in there. Sorry to be an idiot.
As for something like $mp.xp... do you mean I would declare $mp.xp=0 before "Start" and then after "Start" do something like
if mp.xp = 0:
$ mp.xp =
I don't even know what I would put in there. Sorry to be an idiot.
- Aleema
- Lemma-Class Veteran
- Posts: 2677
- Joined: Fri May 23, 2008 2:11 pm
- Organization: happyB
- Tumblr: happybackwards
- Contact:
Re: help! values aren't preserving
Okay, ignore what I said about the Start label, that was some bonus info. What I recommend you do is, in an init block:
Try that? I've never used multipersistent before, but logically, that makes sense.
Code: Select all
if mp.xp is None:
$ mp.xp = 0
Re: help! values aren't preserving
Interesting... it makes the game start with the existing (non-zero) xp amount, even when I delete persistent.
I'm thinking I can make it all work with regular variables and just substitute in some $mp. variables at the end of the game? Couldn't I just have $xp=100 and then say $mp.xp=xp in the final label of the game?
I'm thinking I can make it all work with regular variables and just substitute in some $mp. variables at the end of the game? Couldn't I just have $xp=100 and then say $mp.xp=xp in the final label of the game?
Re: help! values aren't preserving
Okay, scratch that. I had some extra test variables in there that were screwing things up.
If I use "if mp.xp is None..." the game saves with some additional xp that shouldn't be there; if I don't, it resets to zero.
Back to the drawing board I guess. I appreciate your help...
If I use "if mp.xp is None..." the game saves with some additional xp that shouldn't be there; if I don't, it resets to zero.
Back to the drawing board I guess. I appreciate your help...
Who is online
Users browsing this forum: No registered users