Can I use the Call action to pass a variable to a process/label?

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
GammaBreak
Regular
Posts: 62
Joined: Thu Aug 06, 2020 10:04 pm
Contact:

Can I use the Call action to pass a variable to a process/label?

#1 Post by GammaBreak » Sun Dec 27, 2020 6:10 pm

Hi everyone,
I'm working on some conceptual stuff, and I'm trying to sorta make a 'dress up' model where a user can apply different layers via a simple interface at the side of the screen. In the grand scheme of things, there will be checks and balances to prevent conflicting layers and whatnot, but this is purely educational/conceptual for now.

My question is how can I use a screen to pass a variable to a separate label/subroutine? I have a screen menu, it pops up, I select the option, ???, then profit. I'm not fully understanding the Renpy documention here. Using my sample below, I can get my screen to call my label/subroutine, but that's all I can do; I can't get any arguments or keyword arguments to pass, although I'm not fully sure how that works with the Call action. I try to do something like action Call("apply_item", glasses) and it crashes.

My overall desired algorithm:
1. User hits menu/calls it on their own.
2. Selects item from menu
3. Layer is applied to (or removed from) the image on the screen.
4. Return to menu

Below is my trial code:

Code: Select all

define m = Character("Model", who_color="#ffd27c", who_outlines=[(0, "#000", 2, 2)])
image model base = "images/model_base.png"

screen dress_screen(glasses, shirt, pants):
    frame:
        xalign 0.95 ypos 50
        vbox:
            textbutton _("Glasses"):
                action Call("apply_item")
            textbutton _("Shirt"):
                action Call("apply_item")
            textbutton _("Pants"):
                action Call("apply_item")
 
label start:
    #initialization
    $ glasses= False
    $ shirt= False
    $ pants= False
    scene black
    show model base at center
    m "New model"
    call screen dress_screen(glasses, shirt, pants)
    r "Done"
    return

label apply_item:
    #Check for layer conflicts
    #Apply image here
    m "applied"

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Can I use the Call action to pass a variable to a process/label?

#2 Post by _ticlock_ » Sun Dec 27, 2020 6:50 pm

Hi, GammaBreak,

I am not sure that your approach is the best way to do what you want. I think it is much easier to use layeredimage with variables that control the clothes. Then all you need is to change the value of the corresponding variable as action in your dress_screen (SetVariable or ToggleVariable):

Code: Select all

layeredimage li:
    ...
    if glasses:
        "glasses.png"
        
screen dress_screen(glasses, shirt, pants):
    frame:
        xalign 0.95 ypos 50
        vbox:
            textbutton _("Glasses"):
                action ToggleVariable("glasses", True, False)

GammaBreak
Regular
Posts: 62
Joined: Thu Aug 06, 2020 10:04 pm
Contact:

Re: Can I use the Call action to pass a variable to a process/label?

#3 Post by GammaBreak » Sun Dec 27, 2020 6:55 pm

I am not sure that your approach is the best way to do what you want.
And that's why I'm here!

Thanks for the lead on Layered Images. Someone had mentioned using .psd files in Renpy, and I didn't fully understand what they were referring to. This may be the exact thing I'm looking for and need.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Can I use the Call action to pass a variable to a process/label?

#4 Post by _ticlock_ » Sun Dec 27, 2020 7:00 pm

About your question with Call: You can pass param like this:

Code: Select all

screen test():
    vbox:
        textbutton "textbutton num 5" action Call('tt',5)
        textbutton "textbutton num 4" action Call('tt',4)

label start:
    call screen ttt

label tt(num):
    "num is [num]"
    jump start
EDIT:
In your case Call("apply_item", glasses) passes True or False to the label apply_item.
If you try Call("apply_item", 'glasses'), then label apply_item can get string 'glasses':

Code: Select all

label apply_item(item_name):
...

GammaBreak
Regular
Posts: 62
Joined: Thu Aug 06, 2020 10:04 pm
Contact:

Re: Can I use the Call action to pass a variable to a process/label?

#5 Post by GammaBreak » Sun Dec 27, 2020 7:27 pm

I got your code to run, and I think that would potentially work.

My next problem is that I have some variability to deal with. Like you can't wear some items with others, so I need for the screen to be able to check the current attributes, then notify the player if that can't be applied. It needs to be more than just a simple on/off toggle for each thing. Additionally, I'd like the character to be able to react with dialogue when things are added/removed, or for narration to occur.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Can I use the Call action to pass a variable to a process/label?

#6 Post by _ticlock_ » Sun Dec 27, 2020 9:27 pm

GammaBreak wrote:
Sun Dec 27, 2020 7:27 pm
I got your code to run, and I think that would potentially work.

My next problem is that I have some variability to deal with. Like you can't wear some items with others, so I need for the screen to be able to check the current attributes, then notify the player if that can't be applied. It needs to be more than just a simple on/off toggle for each thing. Additionally, I'd like the character to be able to react with dialogue when things are added/removed, or for narration to occur.
I would do something like:

Code: Select all

layeredimage li:
    always:
        "base_image"
    if glasses:
        "glasses.png"
    ...
    
screen dress_screen(glasses, shirt, pants):
    frame:
        xalign 0.95 ypos 50
        vbox:
            textbutton _("Glasses"):
                action Return("glasses")
            textbutton _("Shirt"):
                action Return("shirt")
            textbutton _("Pants"):
                action Return("pants")
 
label start:
    #initialization
    $ glasses= False
    $ shirt= False
    $ pants= False
    scene black
    show model base at center
    m "New model"
    jump dress_label


label dress_label:
    show li
    call screen dress_screen()
    $ returned_attribute = _return
    #Check for layer conflicts
    if conflict:
        m 'Can't be applied'
    else:
        #Change glasses, shirt, pants variable if no conflict
        m "applied"
    if continue_dressing:
        jump dress_label # to continue dress_up
    else:
        jump next_label


GammaBreak
Regular
Posts: 62
Joined: Thu Aug 06, 2020 10:04 pm
Contact:

Re: Can I use the Call action to pass a variable to a process/label?

#7 Post by GammaBreak » Sun Dec 27, 2020 9:39 pm

Great, thanks! Learning a lot right now.

Last question for now, regarding some basic screen styling, then I'll go back to fleshing out my design: how can I get my screen to highlight if an option is active or not? So for example, if the model is wearing the glasses, the glasses button should be highlighted next time the menu pops up, indicating that it's already active and that another click will deactivate it.

I've found how to do some basic styles for the screen, but I'm looking into defining a general style for the entire screen so I don't have to type it all individually for each button in the screen itself.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Can I use the Call action to pass a variable to a process/label?

#8 Post by _ticlock_ » Sun Dec 27, 2020 10:29 pm

GammaBreak wrote:
Sun Dec 27, 2020 9:39 pm
Great, thanks! Learning a lot right now.

Last question for now, regarding some basic screen styling, then I'll go back to fleshing out my design: how can I get my screen to highlight if an option is active or not? So for example, if the model is wearing the glasses, the glasses button should be highlighted next time the menu pops up, indicating that it's already active and that another click will deactivate it.

I've found how to do some basic styles for the screen, but I'm looking into defining a general style for the entire screen so I don't have to type it all individually for each button in the screen itself.
  • You can use style_prefix and then define all corresponding styles
  • texbutton has property selected that defines if the button is selected or not. You can highlight used this property.
Example:

Code: Select all

screen dress_screen(glasses, shirt, pants):
    frame:
        style_prefix "dress"
        xalign 0.95 ypos 50
        vbox:
            textbutton _("Glasses"):
                selected glasses == True   # the button in selected if glasses == True
                action Return("glasses")
          ...
          
style dress_button is gui_button
style dress_button_text is gui_button_text

style dress_button:
    background "#006"
style dress_button_text:
    color "#fff"
    selected_color "#ff0"


GammaBreak
Regular
Posts: 62
Joined: Thu Aug 06, 2020 10:04 pm
Contact:

Re: Can I use the Call action to pass a variable to a process/label?

#9 Post by GammaBreak » Mon Dec 28, 2020 3:48 pm

Great, thanks for all your help!

Post Reply

Who is online

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