Error with 'if' / 'elif' statements (assigning pronouns)

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
User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Error with 'if' / 'elif' statements (assigning pronouns)

#1 Post by zomgenius »

Hello, folks!

I'm creating a game in which the player can select from masculine, feminine, or neutral pronouns. I've tried to come up with an 'if' statement, based off the player's selection in a menu. My goal is to be able to write the story by using pronouns as variables, such as "[They] walked back to [their] room, hoping that [they'll] find the answer." That way, the game would replace the they / their / they'll with he / his / he'll, or she / her / she'll as necessary.

Here's a sample of the code.

Code: Select all

label pronounselectb:

"{i}Please select your preferred pronouns.{/i}"

menu:
    "he / him / his":
        $ pronoun = 'masculine'
    "she / her / hers":
        $ pronoun = 'feminine'
    "they / them / theirs":
        $ pronoun = 'neutral'
        
if pronoun == "masculine":
    $ they = "he"
    $ them = "him"
    $ their = "his"
    $ they're = "he's"
    $ they'll = "he'll"
    $ They = "He"
    $ Them = "Him"
    $ Their = "His"
    $ They're = "He's"
    $ They'll = "He'll"
    $ are = "is"
    $ san = "kun"

elif pronoun == "feminine":
    $ they = "she"
    $ them = "her"
    $ their = "hers"
    $ they're = "she's"
    $ they'll = "she'll"
    $ They = "She"
    $ Them = "Her"
    $ Their = "Hers"
    $ They're = "She's"
    $ They'll = "She'll"
    $ are = "is"
    $ san = "chan"

elif pronoun == "neutral":
    $ they = "they"
    $ them = "them"
    $ their = "their"
    $ they're = "they're"
    $ they'll = "they'll"
    $ They = "They"
    $ Them = "Them"
    $ Their = "Their"
    $ They're = "They're"
    $ They'll = "They'll"
    $ are = "are"
    $ san = "san"
          
"I circled the option for [pronoun] pronouns, since I prefer to use [they] / [them] / [their]."
However, I'm getting the following errors:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/prologue.rpy", line 234: invalid syntax
(Perhaps you left out a " at the end of the first line.)
    they're = "he's"
                  ^
    

File "game/prologue.rpy", line 240: invalid syntax
(Perhaps you left out a " at the end of the first line.)
    They'll = "He'll"
                  ^
    

File "game/prologue.rpy", line 253: invalid syntax
(Perhaps you left out a " at the end of the first line.)
    They're = "She's"
                   ^
    

File "game/prologue.rpy", line 263: invalid syntax
(Perhaps you left out a " at the end of the first line.)
    they'll = "they'll"
My assumption is that it has something to do with the apostrophes in the They're / They'll / etc. when trying to define the pronouns. (It worked fine before trying to add those options.) However, I've tried everything I can think of to fix it - backslashes, containing them within double-quotes, changing the double-quotes to single quotes... Nothing seems to be doing the trick, and my Google-fu isn't up to par today.

Could someone help point me in the right direction to get this fixed? Alternatively, if there are better ways to go about assigning pronouns in a story, could someone direct me to places I might learn more? Thanks in advance for your help!!
Image
Paper Stars: A Visual Novel
What do you wish for?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Error with 'if' / 'elif' statements (assigning pronouns)

#2 Post by trooper6 »

You may want to check out this article by PyTom
https://patreon.renpy.org/python-tricks-1.html

also, you don't need the they'll variables. Because in text you can just do "I'm sure [they]'ll be fine."
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

User avatar
Marionette
Regular
Posts: 128
Joined: Thu Apr 21, 2011 12:04 pm
Completed: https://marionette.itch.io/
Projects: Get Meowt of Here
Deviantart: rexx9224
itch: marionette
Location: Ireland
Discord: Marionette#2995
Contact:

Re: Error with 'if' / 'elif' statements (assigning pronouns)

#3 Post by Marionette »

Based on the errors you are getting the issue is that you are not escaping your ' s, so the code is basically trying to make a new string between two instances of those causing issues.

Try changing your options to He\'ll, She\'ll or They\'ll etc

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Error with 'if' / 'elif' statements (assigning pronouns)

#4 Post by rames44 »

Phrased differently, the apostrophe is not a valid character in a variable name. So when Ren’py sees

$ They’ll = ...

It parses it as
Token 1: $
Token 2: They
Token 3: String containing “ll =...

and, of course, a variable name (They) immediately followed by a string is a syntax error.

Your best bet is not to include the apostrophes in the variable names:

$ Theyll = “They'll”

Even if Python allows you to put them in using escapes (which I’m not sure works) it’s going to be a pain.

User avatar
zomgenius
Regular
Posts: 27
Joined: Mon Apr 16, 2012 11:32 pm
Projects: Paper Stars
Location: USA
Contact:

Re: Error with 'if' / 'elif' statements (assigning pronouns)

#5 Post by zomgenius »

Thank you all for your help! I was able to get it to work. I had to remove the apostrophe from the variable, and then escape what the replacement would be.

Still, I'm going to look into the link trooper provided - there's probably a better way to do this, which makes it a little more clean. Thanks again!
Image
Paper Stars: A Visual Novel
What do you wish for?

Post Reply

Who is online

Users browsing this forum: No registered users