Defining LayeredImage when image requires two attributes?

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
User avatar
yon
Regular
Posts: 153
Joined: Tue Sep 09, 2014 5:09 pm
Projects: YDSP
Location: United States
Contact:

Defining LayeredImage when image requires two attributes?

#1 Post by yon » Sun Oct 09, 2022 5:00 pm

Hi all,

I'm trying to implement layeredimage sprites to save on file size, but I have no idea how to implement this when it comes to how my outfits are set up

Outfits are split into "cold" and "warm", but then ALSO "uniform" and "casual". Which is to say, the casual outfit a character wears in winter requires both "cold" and "cas" to be true. So how am I supposed to set that up in the code?

An obvious solution might be "just do cold_cas or something", and use cold_cas as the attribute, but I don't think that will work, because the sprite being displayed requires code which determines what the weather is, then automatically picks between cold and warm. The code I use is here:

Code: Select all

$ renpy.show("ani {} cas neutralright".format(v_clothes))
    with dissolve
and v_clothes is defined elsewhere in the code, which changes at certain points in the game as so:

Code: Select all

$ v_clothes = "cold"
Would the solution then just be changing the code to

Code: Select all

$ renpy.show("ani {}_cas neutralright".format(v_clothes))
    with dissolve
And then setting cold_cas as the attribute? Would that work? Or is there a different way of setting up the attributes that wouldn't require changing that the renpy.show code?

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

Re: Defining LayeredImage when image requires two attributes?

#2 Post by _ticlock_ » Mon Oct 10, 2022 12:15 pm

If you are setting up v_clothes, I would suggest considering using if statements in the layeredimage:

EDIT: It turned out that if statements do not work inside group or attribute. I updated code to use substitution instead.

Code: Select all

layeredimage ani:
    ...
    group outfit:
        attribute cas:
            "[v_clothes]_cas_outfit"
        attribute uni:
            "[v_clothes]_uni_outfit"
However, you have to change your show statements

Code: Select all

$ renpy.show("ani cas neutralright")
I believe there is a reason why you are using renpy.show, so I am not questioning that.
You can actually still use your old show statements if you don't want to change them. For example, by using "fake" attribute ("cold","warm"), that does not change the image.

(2) Using <cold>_<cas> also should work as you suggested, but in this case if you are going to specify <cold> and <cas> as variables, it is also more convenient to use if statements in the layeredimage:

Code: Select all

layeredimage ani:
    ... 
       if v_clothes == "cold_cas":
                "cold_cas_outfit"
        elif v_clothes == "warm_cas":
                "warm_cas_outfit"
        ...
Or using 2 variables could be more convenient:

Code: Select all

layeredimage ani:
    ... 
       if v_clothes_season == "cold" and v_clothes == "cas":
            "cold_cas_outfit"
        elif v_clothes_season == "cold" and v_clothes == "uni":
            "cold_uni_outfit"
        elif v_clothes_season == "warm" and v_clothes == "cas":
            "warm_cas_outfit"
        elif v_clothes_season == "warm" and v_clothes == "uni":
            "warm_uni_outfit"

                ...

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]