What does define config.adjust_attributes = { } do?

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
MagicBuns
Newbie
Posts: 5
Joined: Mon Dec 18, 2023 5:26 pm
Contact:

What does define config.adjust_attributes = { } do?

#1 Post by MagicBuns »

I'm wondering how to write a python function that automatically changes my characters clothing, without having to write a lengthy set of "if" statements in the layered image.

Apparently the configuration variable

Code: Select all

define config.adjust_attributes = {} 
is crucial to changing the attributes, groups or layers in a layered image, but I don't understand how it works.

Can anyone help explain it to me? Use layman terms where possible. Thank you.

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

Re: What does define config.adjust_attributes = { } do?

#2 Post by m_from_space »

MagicBuns wrote: Tue Apr 16, 2024 4:35 am I'm wondering how to write a python function that automatically changes my characters clothing, without having to write a lengthy set of "if" statements in the layered image.
What do you mean by "automatically". You just said you don't want "if" statements, but then you talk about writing a function for it. You realize that that function still will need if statements if there are any conditions for the clothes. So what is it exactly that is bothering you?

MagicBuns
Newbie
Posts: 5
Joined: Mon Dec 18, 2023 5:26 pm
Contact:

Re: What does define config.adjust_attributes = { } do?

#3 Post by MagicBuns »

m_from_space wrote: Tue Apr 16, 2024 5:50 am What do you mean by "automatically". You just said you don't want "if" statements, but then you talk about writing a function for it. You realize that that function still will need if statements if there are any conditions for the clothes. So what is it exactly that is bothering you?
That I don't want to keep on writing "if" statements every time the main character changes an item of clothing, as there will be a lot more clothing. So, everything I trying to figure out 'dynamism in attributes', as the ren'py documentation put its in Layered Images (attached link it's right at the bottom).

It seems that the renpy configuration

Code: Select all

define config.adjust_attributes = {}
is important, but I'm wondering how it works, so I can better understand 'dynamism in attributes'.

https://www.renpy.org/doc/html/layeredimage.html

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

Re: What does define config.adjust_attributes = { } do?

#4 Post by m_from_space »

MagicBuns wrote: Tue Apr 16, 2024 8:41 am That I don't want to keep on writing "if" statements every time the main character changes an item of clothing, as there will be a lot more clothing.
Not sure you understand how layered images work, in general you don't have to use any if-statements.

Look at this example: https://www.renpy.org/doc/html/layeredi ... red-images

You just define different outfits by creating "group" and "attribute" and whenever you want your character to wear something in particular, you use that attribute as a tag when showing them.

But maybe you could give us an example on what you are referring to.

MagicBuns
Newbie
Posts: 5
Joined: Mon Dec 18, 2023 5:26 pm
Contact:

Re: What does define config.adjust_attributes = { } do?

#5 Post by MagicBuns »

m_from_space wrote: Wed Apr 17, 2024 5:55 am Not sure you understand how layered images work, in general you don't have to use any if-statements.

But maybe you could give us an example on what you are referring to.
You don't have to use if statements, unless you want to change the default attributes within a layered image, which is what I am trying to explain. I want the player to be able swap clothing, and have it stick. I know I can use layered images, as that link you shared shows, but to give you an example, scroll to the very bottom of that webpage, and you'll see the "config.adjust_attributes = {}" in use. It's used alongside a function, so you don't need a lengthy set of if statements - which is what I will need, because my main character will have a lot of clothing that players can adjust. I can figure out the loop if I try hard enough, but I wondering what that configuration variable does.

Thank you for your time.

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

Re: What does define config.adjust_attributes = { } do?

#6 Post by m_from_space »

MagicBuns wrote: Wed Apr 17, 2024 10:15 amI want the player to be able swap clothing, and have it stick.
It's the first time you mention that you want the player to change the clothes. How am I supposed to know that?

config.adjust_attributes helps you define attributes of layered images depending on contents of variables. This config variable points to a function that is called whenever the layered images with the given attribute is shown or predicted. Here is a little explanation: https://www.renpy.org/doc/html/config.h ... attributes

Let's pick the example and add some comments:

Code: Select all

# define your layered image, named "eileen" in this case
layeredimage eileen:
    attribute base default
    group outfit auto
    group ribbon prefix "ribbon":
        attribute red
        attribute blue

# a variable that defines the color of the ribbon
default eileen_ribbon_color = "red"

# create the adjusting function
init python:
    def eileen_adjuster(names):
        # pick all the attributes
        # the first element at index 0 is not an attribute, but the tag "eileen", so we do not include it
        atts = set(names[1:])
        # if the image is shown with a ribbon tag at the moment
        # let's remove it and replace it with a specific ribbon color saved inside the variable
        if "ribbon" in atts:
            atts.remove("ribbon")
            atts.add("ribbon_" + eileen_ribbon_color)
        # return the tag and the new attributes
        return names[0], *atts

# connect the layered image called "eileen" with the function
define config.adjust_attributes["eileen"] = eileen_adjuster
So given this example, what does it do?

Code: Select all

label start:
    # This does not show any ribbon
    show eileen
    
    # This will show Eileen with the red ribbon, since 'ribbon' will be replaced by 'ribbon_red'
    show eileen ribbon
    
    # This will not change the ribbon on the fly with the current function
    $ eileen_ribbon_color = "blue"
    
    # Only after that it will change to the blue color
    show eileen ribbon
So if you want to use this kind of function, you still will need to write conditions on when to change certain attributes. As I said in the beginning.

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

Re: What does define config.adjust_attributes = { } do?

#7 Post by m_from_space »

MagicBuns wrote: Tue Apr 16, 2024 4:35 am I'm wondering how to write a python function that automatically changes my characters clothing, without having to write a lengthy set of "if" statements in the layered image.
Maybe I should point out, that you don't have to write all if conditions inside the layered image. You can also define images that are based on conditions in the first place and then incorporate them into the layered image.

Example, assuming you have "red_pants.png" and "black_pants.png" in your images folder:

Code: Select all

default pants_color = "black"

image mike_outfit_pants = ConditionSwitch(
    "pants_color == 'red'", "red_pants",
    "pants_color == 'black'", "black_pants",
    # no image/pants when no condition is True
    "True", Null()
)

layeredimage mike:
    always:
        "mike_body"
    group outfit:
        attribute shorts
        attribute pants
        attribute skirt

label start:
    # nude mike
    show mike
    
    # show with black pants
    show mike pants
    
    # change to red pants on the fly
    $ pants_color = "red"

MagicBuns
Newbie
Posts: 5
Joined: Mon Dec 18, 2023 5:26 pm
Contact:

Re: What does define config.adjust_attributes = { } do?

#8 Post by MagicBuns »

m_from_space wrote: Thu Apr 18, 2024 6:39 am It's the first time you mention that you want the player to change the clothes. How am I supposed to know that?
Sorry, I should have been clearer. I thought I was at first. Either way, the ConditionSwitch, as well as the explanation of what the config variable does, was helpful. Thank you! :mrgreen: :mrgreen: :mrgreen:

Post Reply

Who is online

Users browsing this forum: No registered users