Is it possible to pass on a parameter to a another 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
SLim_Games
Newbie
Posts: 23
Joined: Tue Mar 20, 2018 11:37 am
itch: slim-games
Contact:

Is it possible to pass on a parameter to a another screen?

#1 Post by SLim_Games »

Hi,
so you can give a parameter (correct me this is the wrong name) to a screen like

Code: Select all

label test:
	show screen testscreen("image.png")
	
screen testscreen(pic1):
	add pic1
My question is if it is possible to give that parameter to another screen when I call a screen with a screen like:

Code: Select all

screen test1(pic1):
	imagemap:
		ground "image.png"
		action Show("screen2(pic1)")
		
screen test2(pic2):
	add pic2
is there a way to pass over the parameter?
Play my game (nsfw) for free at: https://www.patreon.com/SLim_Games

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Is it possible to pass on a parameter to a another screen?

#2 Post by Remix »

action [ Function( renpy.show_screen, "test2", pic1 ) ]
Frameworks & Scriptlets:

SLim_Games
Newbie
Posts: 23
Joined: Tue Mar 20, 2018 11:37 am
itch: slim-games
Contact:

Re: Is it possible to pass on a parameter to a another screen?

#3 Post by SLim_Games »

Remix wrote: Sat Jun 09, 2018 3:24 am action [ Function( renpy.show_screen, "test2", pic1 ) ]
thank you soooo much :D you saved my life :)
Play my game (nsfw) for free at: https://www.patreon.com/SLim_Games

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

Re: Is it possible to pass on a parameter to a another screen?

#4 Post by kivik »

Remix, I'm going to disagree on this one! :o

According to the docs: https://www.renpy.org/doc/html/screen_actions.html#Show

Code: Select all

Show(screen, transition=None, *args, **kwargs) link
You can use pass additional arguments and keyword arguments. So in your example OP this should work:

Code: Select all

action Show("test2", pic1) # you showed us a screen called test2 not screen2
If it doesn't, then you should definitely get it work adding the keyword for the parameters:

Code: Select all

action Show("test2", pic2=pic1)
OP: Just to clarify, you don't need to give your screen / function parameters different parameter names (pic1 in test1, pic2 in test2). Parameters are treated as "local variables" and not global, which means within the screen, your parameter name is safe to be used without colliding with any global variables with the same name. Try just using pic as the parameter names and you'll see the code works fine - and you'll save yourself managing a load of different variable names for every screen / function you create :)

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Is it possible to pass on a parameter to a another screen?

#5 Post by Remix »

Ah, the good old "reply before checking whether the other Action supports parameters" mistake... oops.
(must have had it muddled with inline show or some other thing)

So saying, the Function action is generally a good one to teach (and learn) as it always supports passig *args and **kwargs.

Well spotted though kivik
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Google [Bot], LegsWild, Ocelot