How to reset a variable to default

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.
Post Reply
Message
Author
bdaywans
Newbie
Posts: 15
Joined: Sat Jul 13, 2019 2:54 pm
Contact:

How to reset a variable to default

#1 Post by bdaywans » Fri Jul 26, 2019 6:15 pm

I was under the impression that variables would reset at the end of a call but I think I misunderstood. Here's my situation.

I the player will call a minigame and I finally got it working properly. During the minigame wins/losses will effect the players stats: more money, skills etc.

But DURING the game I have a series of local variables that need to reset at the end of the game. I thought it was going to reset but when I call the minigame again the next day (I have a setting that it can only be plated once a day) it retains the image settings from the last day. My sloppy solution was to just set the variables back to zero (or 1 respectively) when the NewDay function was called. The day resets, the ability to play the game resets, but the variables dont...

I'm trying to figure out what I can do to tell the game to reset the minigame variables at the end of the minigame.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1340
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: How to reset a variable to default

#2 Post by namastaii » Fri Jul 26, 2019 6:31 pm

I'm not sure if there is a code specifically but you could make your own? create a function and list all the variables within the function to get set to 0 or whatever it need be and you can call that function when needed? or include it more specifically in your newday function. I haven't messed with persistent stuff but you could try persistent._clear()?

User avatar
Kia
Miko-Class Veteran
Posts: 912
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Skype: KiaAzad
Contact:

Re: How to reset a variable to default

#3 Post by Kia » Sat Jul 27, 2019 1:15 am

the solution is defining your variables inside the minigame screen, if your minigame is a screen of course.
this way every time you open your minigame, the variables are re-assigned.
if your minigame does not have a screen, it should be contained inside a label and the variables defined at the top of the label

Post Reply

Who is online

Users browsing this forum: Google [Bot]