I have a game where the player is able to input their own name with this code:
$ player_name = renpy.input ("What is your name?")
$ player_name = player_name.strip()
I call the name in the script using %(player_name)s.
I also have a variable in the game where the player can gain "points" or "achievements" or whatever you want to call it. It's defined like this:
$ clues = 0
And then throughout the script I add to it with $ clues += 1.
Everything works great when I run the game up until I close the window to make edits. Then, all variables are lost. Is there a way to keep this from happening? For a while, it was working great. I could close the game and walk away for a few days, and when I came back the "player_name" and "clues" variables would still be set and I wouldn't have to start from the beginning. I don't know what I did, but somewhere along the way that stopped. I'm assuming that it has something to do with saving the game state, but I've been reading renpy tutorials for weeks and haven't been able to find an answer that works.
Does anybody out there have any suggestions?
Saving Player Input
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.
-
- Newbie
- Posts: 3
- Joined: Fri Jul 20, 2018 1:39 pm
- Contact:
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: Saving Player Input
define your variables with default outside any label and the saves will remember them.
In any case, you have to save your game.
Code: Select all
default player_name = ""
default clues = 0
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
-
- Newbie
- Posts: 3
- Joined: Fri Jul 20, 2018 1:39 pm
- Contact:
Re: Saving Player Input
That works for the clues, but if I set a default player name, then that's the name that renpy displays instead of the player input. Is there a way for renpy to remember the player input name instead of falling back to a set default?
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: Saving Player Input
The problem must be elsewhere. Whatever the player enters, it will overwrite the default value.
When a new game is started, the variable has the default value. The renpy.input must be at the beginning of the game; that value won't be remembered in new games but it will if you save and load that game. Are you loading or clicking on "start"?
When a new game is started, the variable has the default value. The renpy.input must be at the beginning of the game; that value won't be remembered in new games but it will if you save and load that game. Are you loading or clicking on "start"?
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
-
- Newbie
- Posts: 3
- Joined: Fri Jul 20, 2018 1:39 pm
- Contact:
Re: Saving Player Input
I'm just clicking on "Start". When I was trying to load saved files earlier it was working, but I've messed with it quite a bit since then and haven't checked to see if it's still working lol.
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: Saving Player Input
If you click start, the game starts from zero; variables have their "default" value; the "player_name" will have a useful value only after you reach the renpy.input line and renpy asks you for a name. Any name you put on former games is irrelevant because the game is starting from zero. The same will happen to your players when they play the game.
If you want to reuse a value among different saves you need to use "persistent", but that's not what you need in this case.
If you want to reuse a value among different saves you need to use "persistent", but that's not what you need in this case.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Saving Player Input
Here is working code that explains this. Put it in a fresh project.
Code: Select all
define pc = Character("[pc_name]")
default pc_name = "Unknown"
# The game starts here.
label start:
scene black
pc "The game begins. Who is speaking? Unknown! The name is unknown because
that is the default and we haven't changed it yet. It will always be Unknown
for any new game."
pc "But let's change our name."
$pc_name = renpy.input("What is my name?")
$pc_name = pc_name.strip()
pc "So my name is [pc_name]."
pc "Intersting!"
pc "Okay this is what I want you do do now. I want you do save the game at
this point and then quit. After you quit, restart the game and load the save."
pc "Are you back?"
pc "You'll notice that my name is still [pc_name]!"
pc "Because the variable is saved!"
pc "In this playthrough, it will remain [pc_name] and won't go back to Unknown."
pc "If you finish the game and want to play a brand new game with a new name
for me, you can!"
pc "Okay, the game if finished. Bye!"
return
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot]