Is There a Limit on the Number of If Statements?

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
RoboKnight
Newbie
Posts: 19
Joined: Sun Feb 18, 2018 6:12 pm
Contact:

Is There a Limit on the Number of If Statements?

#1 Post by RoboKnight » Tue Feb 20, 2018 3:31 am

So in the beginning of my game, I have several...safety barriers...in order to prevent people from naming themselves certain things (aka my friend input the N-word when he playtested my game for the first time) and some easter eggs if friends of mine input their (very specific) nicknames. I end up with 5 (only 4 will be shown so I don't have a bunch of expletives here) If statements, but after the third If statement, all my other conditions go straight to said third If statement. Here is my code:

Code: Select all

label start:

     scene bg black
     
     label game_start:
     
    $ player_name = renpy.input("What is your name?", length=14)
    $ player_name = player_name.strip()
    $ player_name = player_name.upper()
    if player_name == "ARTHUR":
        "Ah, so perhaps you remember...But nevermind that."
    if player_name == "":
        "You do not remember your name? Then you shall be granted one that may spark your memory..."
        $ player_name = "Arthur"
    if player_name == "JADE", "BRAD", "BRIAN", "PHIPPEN", "SHARON", "STUDENT":
        "Sincere apologies, but that name is already taken."
        jump game_start
    if player_name == "BOMBERBLU":
        "Try again, Ben."
        jump game_start
If I input "bomberblu", then the response I receive is "Sincere apologies, but that name is already taken." Is there a way to get around this? Changing the last three If statements to "elif" doesn't change anything.

User avatar
IrinaLazareva
Veteran
Posts: 246
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy, Эра Тёмных Небес
Organization: IKG
Location: St.Petersburg, Russia
Contact:

Re: Is There a Limit on the Number of If Statements?

#2 Post by IrinaLazareva » Tue Feb 20, 2018 4:13 am

try

Code: Select all

    if player_name == "ARTHUR":
        "Ah, so perhaps you remember...But nevermind that."
    elif player_name == "":
        "You do not remember your name? Then you shall be granted one that may spark your memory..."
        $ player_name = "Arthur"
    elif player_name in ["JADE", "BRAD", "BRIAN", "PHIPPEN", "SHARON", "STUDENT"]:
        "Sincere apologies, but that name is already taken."
        jump game_start
    elif player_name == "BOMBERBLU":
        "Try again, Ben."
        jump game_start
https://docs.python.org/2/tutorial/intr ... html#lists
https://docs.python.org/2/tutorial/cont ... statements
https://www.renpy.org/doc/html/conditio ... -statement
There is a light at the end of the tunnel, just pray it's not a train.

RoboKnight
Newbie
Posts: 19
Joined: Sun Feb 18, 2018 6:12 pm
Contact:

Re: Is There a Limit on the Number of If Statements?

#3 Post by RoboKnight » Tue Feb 20, 2018 4:51 am

IrinaLazareva wrote:
Tue Feb 20, 2018 4:13 am
try

Code: Select all

    if player_name == "ARTHUR":
        "Ah, so perhaps you remember...But nevermind that."
    elif player_name == "":
        "You do not remember your name? Then you shall be granted one that may spark your memory..."
        $ player_name = "Arthur"
    elif player_name in ["JADE", "BRAD", "BRIAN", "PHIPPEN", "SHARON", "STUDENT"]:
        "Sincere apologies, but that name is already taken."
        jump game_start
    elif player_name == "BOMBERBLU":
        "Try again, Ben."
        jump game_start
https://docs.python.org/2/tutorial/intr ... html#lists
https://docs.python.org/2/tutorial/cont ... statements
https://www.renpy.org/doc/html/conditio ... -statement
Like I've mentioned, using "elif" does nothing (sorry for the late reply, I didn't see it)

User avatar
Draziya
Regular
Posts: 64
Joined: Sun Nov 26, 2017 8:50 am
Completed: I Don't Have A Clue [QRMJam 18], Cautionary Tale [NaNoRenO 18], OP Dodge Cross [GGJ 18], Acetone [AceJam 18], Ah! My Girlfriend is a Demon Summoned from the Depths of Hell! [MonJam 17]
Organization: Watercress
itch: Drazillion
Contact:

Re: Is There a Limit on the Number of If Statements?

#4 Post by Draziya » Tue Feb 20, 2018 4:56 am

Whether elif does or does not do anything doesn't really matter, in this case. Irena put square brackets around the Jade, Brad etc statement, which should fix the problem.

When I was doing my own testing with your code, I too, found out that the problem was with that particular if statement. It meant that even if I didn't input a name, it still said it was already taken! I fixed it with a similar solution (using normal brackets not square)
Image

RoboKnight
Newbie
Posts: 19
Joined: Sun Feb 18, 2018 6:12 pm
Contact:

Re: Is There a Limit on the Number of If Statements?

#5 Post by RoboKnight » Tue Feb 20, 2018 5:00 am

Draziya wrote:
Tue Feb 20, 2018 4:56 am
Whether elif does or does not do anything doesn't really matter, in this case. Irena put square brackets around the Jade, Brad etc statement, which should fix the problem.

When I was doing my own testing with your code, I too, found out that the problem was with that particular if statement. It meant that even if I didn't input a name, it still said it was already taken! I fixed it with a similar solution (using normal brackets not square)
Wow I really should've listened to my doctor when he said I needed glasses lol. I didn't even notice the brackets!! Thank you for pointing out they were there, or else I would've rotted in this chair, forever stumped TT.TT
Sorry Irena >.>

EDIT: everything worked, except for when I tried to put brackets around my 29-word long list of expletives (in the same format as the "Jade, Brad, etc.)...it would just say "Welcome to your journey (censored)!" (censorship for this forum, not in the program)

User avatar
Draziya
Regular
Posts: 64
Joined: Sun Nov 26, 2017 8:50 am
Completed: I Don't Have A Clue [QRMJam 18], Cautionary Tale [NaNoRenO 18], OP Dodge Cross [GGJ 18], Acetone [AceJam 18], Ah! My Girlfriend is a Demon Summoned from the Depths of Hell! [MonJam 17]
Organization: Watercress
itch: Drazillion
Contact:

Re: Is There a Limit on the Number of If Statements?

#6 Post by Draziya » Tue Feb 20, 2018 6:59 am

Oops, forgot to also point out that it's not just the brackets that do the trick, but also the fact that it's

Code: Select all

in ["JADE", "BRAD", "BRIAN", "PHIPPEN", "SHARON", "STUDENT"]:
not

Code: Select all

== ["JADE", "BRAD", "BRIAN", "PHIPPEN", "SHARON", "STUDENT"]:
You want the code to see if a string is in a list, not that a string somehow equals an entire list.
Image

RoboKnight
Newbie
Posts: 19
Joined: Sun Feb 18, 2018 6:12 pm
Contact:

Re: Is There a Limit on the Number of If Statements?

#7 Post by RoboKnight » Fri Feb 23, 2018 3:24 am

Oh it works now! Thank you! My eyes definitely skipped over the "in" keyword. Thank you so much again for pointing that out for me!

Post Reply

Who is online

Users browsing this forum: No registered users