How to pass a variable to the button action when calling the 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
span4ev
Regular
Posts: 77
Joined: Fri Jul 08, 2022 9:29 pm
itch: rpymc
Contact:

How to pass a variable to the button action when calling the screen?

#1 Post by span4ev » Wed Jul 13, 2022 12:08 am

Code: Select all

screen statsNames():
    
    for i in range(len(open_persons_list)):

        $ current_class_name = open_persons_list[i]

        textbutton current_class_name:

            # I want to put it here and use the variable in another screen, but I don't understand how to do it.
            # I get an error "str object is not callable"
            #                           |
            #                           |
            #                          \ /
            hovered Show('test(current_class_name)')

            action NullAction()

screen test(class_name):
    frame:
        text class_name
usually without passing arguments it works like this:

hovered Show('statsDetail')

I've tried a bunch of different options but i don't understand this syntax

Code: Select all

hovered Show('test(current_class_name)')
hovered Show('test[current_class_name]')
hovered Show('test([current_class_name])')
hovered Show('test', 'current_class_name')
hovered Show('test', current_class_name)
hovered Show('test', $ current_class_name)
hovered Show('test', [current_class_name])
hovered Show('test', [$ current_class_name])
hovered Show('test', '[$ current_class_name]')
hovered Show('test', ['current_class_name'])
hovered Show('test', '[current_class_name]')

User avatar
m_from_space
Veteran
Posts: 302
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to pass a variable to the button action when calling the screen?

#2 Post by m_from_space » Wed Jul 13, 2022 7:48 am

Use keywords arguments:

Code: Select all

Show('test', class_name=current_class_name)

span4ev
Regular
Posts: 77
Joined: Fri Jul 08, 2022 9:29 pm
itch: rpymc
Contact:

Re: How to pass a variable to the button action when calling the screen?

#3 Post by span4ev » Wed Jul 13, 2022 2:53 pm

m_from_space wrote:
Wed Jul 13, 2022 7:48 am
Use keywords arguments:

Code: Select all

Show('test', class_name=current_class_name)
Thank you very much! You are my hero. It really works. I don't know why the syntax is the way it is, but it is.

Yesterday, out of desperation, I used this approach:

Code: Select all

init python:
    
    def some_func(class_name):
        renpy.show_screen('test', class_name)

screen statsNames():
    
    style_prefix 'statsNames_'
    frame:
        $ class_name = '5555'
        textbutton 'gggg':
            hovered Function(some_func, class_name)
            action NullAction()

screen test(class_name):
    frame:
        text class_name

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: How to pass a variable to the button action when calling the screen?

#4 Post by philat » Wed Jul 13, 2022 7:26 pm

The second argument, if not a keyword arg, is transition. https://www.renpy.org/doc/html/screen_actions.html#Show

span4ev
Regular
Posts: 77
Joined: Fri Jul 08, 2022 9:29 pm
itch: rpymc
Contact:

Re: How to pass a variable to the button action when calling the screen?

#5 Post by span4ev » Thu Jul 14, 2022 7:51 pm

philat wrote:
Wed Jul 13, 2022 7:26 pm
The second argument, if not a keyword arg, is transition. https://www.renpy.org/doc/html/screen_actions.html#Show
I am missing a code example to see how I can use this

Post Reply

Who is online

Users browsing this forum: No registered users