Using a variable inside a screen

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
starlingmaximilian
Newbie
Posts: 15
Joined: Mon Oct 14, 2019 4:07 pm
Contact:

Using a variable inside a screen

#1 Post by starlingmaximilian » Sun Mar 29, 2020 11:00 am

Hi, I'm using a variable called open which is either true or false. This variable is declared at the beginning of the code.
The variable "open" is False by default.

Code: Select all

define y = ("Yukio")
default open = False

label start:
hide screen item
scene bathroom
I then change the value to True (doing certain thing in the game) but when I want to use this variable inside a screen, I just can't.

Code: Select all

screen doorknob():
            tag item
            imagebutton:
                     xalign 0.2 yalign 0.55
                     idle "doorknob.png"
                     action If(("open" == True), true = Jump("living"), false = Jump("start"))  # Here I'm trying to use the variable "open" but the screen doesn't recognize it.

Is there a way I can call the variable "open" in which the screen would recognize it?

User avatar
gas
Miko-Class Veteran
Posts: 686
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Using a variable inside a screen

#2 Post by gas » Sun Mar 29, 2020 11:13 am

Code: Select all

screen doorknob():
            tag item
            imagebutton:
                     xalign 0.2 yalign 0.55
                     idle "doorknob.png"
                     action If((open), true = Jump("living"), false = Jump("start")) 
As an extra note, you don't need to check if somethin is True. It's always True if isn't False. That's why 'if open' suffice.
10 ? "RENPY"
20 GOTO 10

RUN

starlingmaximilian
Newbie
Posts: 15
Joined: Mon Oct 14, 2019 4:07 pm
Contact:

Re: Using a variable inside a screen

#3 Post by starlingmaximilian » Mon Mar 30, 2020 4:55 am

Thank you so much!!!
So, basically, I could just use:

Code: Select all

action If((open), true = Jump("living")
Thanks!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]