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.
Hello! I'm relatively new to coding with Python, but I do have some experience with JavaScript. I feel like that's important.
I tried to watch a tutorial on choosing a character at the start of the game, but I feel like what the creator had doesn't really fit my situation (plus, they're using an older version of Ren'Py). I'm not sure how to make the code remember the character's choice for gender. This is the code I have for this section:
I was just using the labels to go the confirmation question so that the player can see the character sprite for the gender they chose, or if they accidentally misclicked, they can go back to the original question. I had a feeling it had something to do with variables, but I wasn't sure how variables worked in Python. Thank you!
default gender = None
label start:
python:
player = renpy.input(_("What is your name?"))
player= player.strip()
if player == "": # I assume Noel is a default only if the player did not enter anything
player = __("Noel")
menu choose_gender: # probably makes more sense to have the question in the menu and to jump directly to the menu
'What are your pronouns?'
"He/Him":
$ gender = "male"
"She/Her":
$ gender = "female"
"They/Them":
$ gender = "neutral"
show expression "mc_" + gender # show mc_male, mc_female, or mc_neutral
"Are you [gender]"?
menu:
"Yes":
"Okay."
"No":
jump choose_gender
"Next stuff."
I guess I was just amazed that it was that simple. I was looking for a way to shorthand it that didn't involve a whole bunch of if and elif statements, so thank you very much!
default gender = None
label start:
python:
player = renpy.input(_("What is your name?"))
player= player.strip()
if player == "": # I assume Noel is a default only if the player did not enter anything
player = __("Noel")
menu choose_gender: # probably makes more sense to have the question in the menu and to jump directly to the menu
'What are your pronouns?'
"He/Him":
$ gender = "male"
"She/Her":
$ gender = "female"
"They/Them":
$ gender = "neutral"
show expression "mc_" + gender # show mc_male, mc_female, or mc_neutral
"Are you [gender]"?
menu:
"Yes":
"Okay."
"No":
jump choose_gender
"Next stuff."
Both ways work, actually. It's very much a pick-your-poison thing. On a personal level, I prefer custom tailoring gender-based sentences and small sections of scenes, rather than just switching out pronouns (which will also need their own sets of variables for each mention). But to each their own.
For your second point, that's fair. There are many cases where explicit if/elses would be more appropriate. In the OP's example, however, only the image and the last word changed for each label, so it was easily collapsible, so I wanted to point that out.