Conditional statement not working right

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
doodlemancy
Newbie
Posts: 19
Joined: Sun Apr 12, 2015 2:04 am
Projects: Iron Company
Tumblr: doodlemancy
Deviantart: doodlemancy
Location: internet
Contact:

Conditional statement not working right

#1 Post by doodlemancy » Tue Dec 29, 2015 7:34 pm

SOLVED. I'm a space case.
Last edited by doodlemancy on Tue Dec 29, 2015 8:45 pm, edited 3 times in total.

User avatar
Chaotic
Regular
Posts: 30
Joined: Fri Feb 22, 2013 7:32 pm
Location: England, UK
Contact:

Re: Conditional statement not working right

#2 Post by Chaotic » Tue Dec 29, 2015 8:14 pm

I think your only problem is the fact that the menu should be indented so that it's in the same indent block as the stuff within the else statement.

Code: Select all

label killtime:
    if things_remaining == 0:
        jump storyprogress
     else:
        "It looks like I've still got some time to kill."
        menu:
            "Do thing 1." if thing1_available == "True":
                $ thing1_available = "False"
                $ things_remaining =- 1
                jump thing1doing
            "Do thing 2." if thing2_available == "True":
                $ thing2_available = "False"
                $ things_remaining =- 1
                jump thing2doing
            "Do thing 3." if thing3_available == "True":
                $ thing3_available = "False"
                $ things_remaining =- 1
                jump thing3doing

philat
Eileen-Class Veteran
Posts: 1764
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Conditional statement not working right

#3 Post by philat » Tue Dec 29, 2015 8:24 pm

A few things.

1. Minor errors in indentation (e.g., the else is indented one extra space) -- fix those. (I realize they may be the result of editing the code to put up on the forum, but always good to double check anyway.) The indentation of the menu doesn't matter in this case, because if you jump to storyprogress, you'll never get to the menu anyway.

2. While what you have does work, why are you using the strings "True"/"False" rather than the boolean values True/False?

Code: Select all

$ thing1_available = True

menu:
    "Do thing 1." if thing1_available:
         $ thing1_available = False
seems much preferable to me.

3. The reason your loop doesn't work is that you wrote

$ things_remaining =- 1 (wrong)

instead of

$ things_remaining -= 1 (right)

The first statement sets things_remaining to -1 (therefore, things_remaining == 0 is never triggered).

You can check the value of variables, by the way, by pressing shift+o to open the console and typing watch variable (in this case, watch things_remaining).
Last edited by philat on Tue Dec 29, 2015 8:45 pm, edited 1 time in total.

User avatar
doodlemancy
Newbie
Posts: 19
Joined: Sun Apr 12, 2015 2:04 am
Projects: Iron Company
Tumblr: doodlemancy
Deviantart: doodlemancy
Location: internet
Contact:

Re: Conditional statement not working right

#4 Post by doodlemancy » Tue Dec 29, 2015 8:33 pm

philat wrote:While what you have does work, why are you using the strings "True"/"False" rather than the boolean values True/False?
D'oh. That's just me spacing out.
philat wrote:The reason your loop doesn't work is that you wrote

$ things_remaining =- 1 (wrong)

instead of

$ things_remaining -= 1 (right)
GAAAAH THIS WAS IT!! THIS WAS IT!! BUT WHY? I had previously had it the right way before, and Ren'py kept yelling at me about it and telling me it was wrong. I'm so confused. Thank you. I'm going to lie down now.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], hell_oh_world