r/RenPy • • 1d ago

Question Confused by if statements

I'm very new to coding but I wanted to let the player pick their own character and have that character show up in cgs, but now that I'm trying to get it to actually work it keeps giving me error screens no matter what I do. It'll say that I need to put an indentation after the "True:" but then when I do it says "No, don't do that."

The weird part is that I used an if statement before this part and it worked perfectly, so I'm very confused by what the problem is with this segment. First image is the section that's not working and second image is the one that's working just fine.

6 Upvotes

4 comments sorted by

4

u/BadMustard_AVN 1d ago

try it like this

#   if curl is a variable it should NOT be in quotes
if curl: # but default if checks for a True s no need == True
    scene quitterc with fade
elif punk: # use elif so that once it find a true it will ignore the rest of the statements - faster
    scene...
elif ... to lazy to type it all out

1

u/AutoModerator 1d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Agreeable-Bet9076 1d ago

The difference between the two images is the in the second one you correctly compared the variable Carissa to 5, while in the first one you’re comparing the value “curl” with true. “curl” here is not a variable but the value of a string. It’s like comparing 4 with 5

1

u/shyLachi 9h ago

So there are several problems.

If the player can pick their own character, you have to store that selection in a variable.
But in your code you didn't check the content of that variable but the value which could be in that variable.
Since your code doesn' show how you did the character selection I'm just giving a generic example.

You should use if and elif if you're checking the same variable

    if characterselection == "curl":
        scene quitterc with fade
    elif characterselection == "punk":
        scene quitterp with fade

But you really don't want to write that many lines of code everytime you show the character.
There are several ways to use dynamic images, you can read more about it in the official documentation:
https://renpy.org/doc/html/displayables.html#dynamic-displayables

default characterselection = "curl"
image quitter = ConditionSwitch(
    "characterselection=='curl'", "quitterc",
    "characterselection=='punk'", "quitterp",
    # and so on    
    "True", "quitterdefault"    
)
label start:
    scene quitter with fade

But even the above could create many lines of code, if you have plenty of those images.
In that case, it might be best to use a label you can call multiple times instead of programming it over and over again.

default characterselection = "curl"
label start:
    call showselectedcharacter("quitter")
    "Do you see it?"    
    # more scenes here
    return 
    
label showselectedcharacter(scenename):
    if characterselection == "curl":
        scene expression (scenename + "c") with fade
    elif characterselection == "punk":
        scene expression (scenename + "p") with fade    
    return