If statement inside frame causes hbox to error?

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
sparkleface
Newbie
Posts: 9
Joined: Mon Dec 25, 2017 12:37 pm
Contact:

If statement inside frame causes hbox to error?

#1 Post by sparkleface »

I tried this:

Code: Select all

                frame:
                    if True:
                        background Solid("#fff")
                    else:
                        background Solid("#000")
                        
                    has hbox:
                        xfill True
                        xysize (1260, 50)
                        button:
                            xsize 150
                            text "zero"
                            ypos 5
But this results in

Code: Select all

 The has statement may not be given after a child has been supplied.
    has hbox:
       ^
Ren'Py Version: Ren'Py 6.99.14.1.3218
If I take out the if statements, then it'll work fine. I guess I have two questions:

- Why does putting an IF statement like that break renpy

- What is the alternative way to setting a conditional background color like I'm trying to do?

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: If statement inside frame causes hbox to error?

#2 Post by Alex »

Remove has statement

Code: Select all

                frame:
                    if True:
                        background Solid("#fff")
                    else:
                        background Solid("#000")
                        
                    hbox:
                        xfill True
                        xysize (1260, 50)
                        button:
                            xsize 150
                            text "zero"
                            ypos 5

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: If statement inside frame causes hbox to error?

#3 Post by Imperf3kt »

if True
...
If what is true?

Back when I was at school, if ever anybody said something without specifying what they were talking about, my science teacher always replied something like <thing> what"
For example:
student "I'll need ten."
Teacher "ten what, ten Bunsen burners?"
student "No, ten glass beakers!"
Teacher "Then specify what you want."
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

sparkleface
Newbie
Posts: 9
Joined: Mon Dec 25, 2017 12:37 pm
Contact:

Re: If statement inside frame causes hbox to error?

#4 Post by sparkleface »

@Alex, thanks for catching that. You're right, just using hbox is enough.

@Imperf2kt, I don't think the result of the evaluated condition was relevant; using True was just a quick and handy way of having a conditional statement there. Unless this is one of renpy's quirks where using that isn't allowed in screen language?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: If statement inside frame causes hbox to error?

#5 Post by Imperf3kt »

I'm wondering what its purpose is.
If True by itself, it not checking anything, so what does it do?
As far as I see, it checks if the frame is there, so sets the color? If so the else is useless and you need some way to turn the frame on and off - otherwise why have a conditional?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: No registered users