Using a Variable to Show a Layered Image

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
DrexOtter
Newbie
Posts: 2
Joined: Tue Nov 21, 2023 5:01 am
Contact:

Using a Variable to Show a Layered Image

#1 Post by DrexOtter »

Hello! I am attempting to make a variable that holds a layered image. I have two scripts, one is a combat minigame, the other is the dialogue for the scene as well as launching the combat minigame. I want for the dialogue script to determine the layered image that displays in the combat script. Here is the relevant code reduced down to only the stuff that matters.

For the dialog script:

Code: Select all

    show Vincent body_armor head_smile eyes_angry with dissolve

    "He lunges at you and unleashes a barrage of attacks!"

    $ attacker = Vincent # layered image to display during combat. I don't want to change his armor, head, 
                         # or eyes, just bring the same image to the other script.
                         
    # I also tried this variation but it didn't work.
    # $ attacker = Vincent body_armor head_smile eyes_angry
    
    call beginCombat # start combat script.
Here is the combat script:

Code: Select all

default attacker = None

label beginCombat:
    show attacker at shakeChar, center # show the character that was determined in the dialogue script, 
                                       # make it look like he moves with each attack, standing in the center.
The error I'm getting: "NameError: name 'Vincent' is not defined.

All I'm trying to do is make it so the already shown layered image character is picked up by the combat script to allow it to move in order to look like he is lunging forward to attack. The reason I don't simply make the "show" line in the combat script another copy of the layered image with body, head, and eyes, is because I don't want to make a combat script for every single encounter. I want combat to happen with whoever happens to be on screen during the dialogue.

User avatar
m_from_space
Miko-Class Veteran
Posts: 888
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Using a Variable to Show a Layered Image

#2 Post by m_from_space »

DrexOtter wrote: Tue Nov 21, 2023 5:36 am Hello! I am attempting to make a variable that holds a layered image. I have two scripts, one is a combat minigame, the other is the dialogue for the scene as well as launching the combat minigame. I want for the dialogue script to determine the layered image that displays in the combat script. Here is the relevant code reduced down to only the stuff that matters.
This should work.

Code: Select all

    show Vincent body_armor head_smile eyes_angry with dissolve

    "He lunges at you and unleashes a barrage of attacks!"

    $ attacker = "Vincent"
    
    call beginCombat # start combat script.

Code: Select all

default attacker = None

label beginCombat:
    show expression attacker at shakeChar, center

DrexOtter
Newbie
Posts: 2
Joined: Tue Nov 21, 2023 5:01 am
Contact:

Re: Using a Variable to Show a Layered Image

#3 Post by DrexOtter »

Thank you so much! That helped a ton and now I got it all working. I appreciate your help. ^^

Post Reply

Who is online

Users browsing this forum: No registered users