Onlayer with 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
Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Onlayer with a variable?

#1 Post by Onishion »

What I'd like to do is set a variable, and then show/hide images using that variable.

Code: Select all

config.layers = [ 'master', 'MyUniqueLayer2', 'MyUniqueLayer1', 'transient', 'screens', 'overlay' ]
default Var = "MyUniqueLayer1"

if X:
    $ Var = "MyUniqueLayer1"
else:
    $ Var = "MyUniqueLayer2"
    
show MyImage onlayer Var
The above code does not work, says that the layer Var doesn't exist, so the straightforward method doesn't work, but is there some way that I can do this, or am I forced to put if/then chains on each time I show/hide it so that it activates a different "show" or "hide" command with the right layer?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Onlayer with a variable?

#2 Post by xela »

Code: Select all

$ renpy.show("MyImage", layer=Var)
Like what we're doing? Support us at:
Image

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Onlayer with a variable?

#3 Post by Onishion »

Ok, that may work out for my purposes, I'll give it a shot. Thanks!

And just to check, if I want to put an "at Transform" property and in there, like

Code: Select all

show MyImage at MyTransform onlayer Var:
    zoom .5
at_list = [MyTransform"] seems to work so far, but what would be the syntax for adding basic transforms to it like zoom .5, pos 150? Do I have to bundle all that into a prepackaged transform to access them?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Onlayer with a variable?

#4 Post by xela »

Code: Select all

$ renpy.show("MyImage", layer=Var, at_list=[Transform(zoom=.5, xpos=500)])
Like what we're doing? Support us at:
Image

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Onlayer with a variable?

#5 Post by Onishion »

Awesome, thank you.

Post Reply

Who is online

Users browsing this forum: decocloud