Making a screen button conditional on a variable

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
radu32167
Newbie
Posts: 24
Joined: Wed Nov 23, 2016 10:25 am
Contact:

Making a screen button conditional on a variable

#1 Post by radu32167 »

Hi I'm wondering if anyone can help me.
I want to make part of a gamescreen only appear if a variable is true.

Code: Select all

screen nonhousescreen:
            textbutton(""):
                area(1, 400, 200, 50)
                background "gui/button/payoff.png"
                hover_background "gui/button/payoffa.png"   
            
                action Call("payoff")
            

            
            textbutton(""):
                area(1600, 900, 200, 50)
                background "gui/button/City.png"
                hover_background "gui/button/Citya.png"   
            
                action Jump("City")       
            
            use days                
If I want the city button to only appear if variable "a" is true. How would I do that?

Thanks in advance

KingsCard
Newbie
Posts: 14
Joined: Sat Feb 17, 2018 8:58 am
Contact:

Re: Making a screen button conditional on a variable

#2 Post by KingsCard »

Code: Select all

label start:
    $ a = False
    show screen nonhousescreen
    "hello"
    $ a = True
    "Where did you go ?!"

screen nonhousescreen:
    if a:
        textbutton "Hi" action NullAction

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Making a screen button conditional on a variable

#3 Post by kivik »

You can also use showif: https://www.renpy.org/doc/html/screens. ... -statement

You probably won't need it, but basically it passes the condition to any children in the block, so that you can do transform to them (like starting animation when shown).

radu32167
Newbie
Posts: 24
Joined: Wed Nov 23, 2016 10:25 am
Contact:

Re: Making a screen button conditional on a variable

#4 Post by radu32167 »

Worked

Thank you very much

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]