[Sovled] DynamicDisplayables and Live Composites

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
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

[Sovled] DynamicDisplayables and Live Composites

#1 Post by HB38 »

So, I was almost completely set with my variables in my project when I ran across this use case:

Code: Select all


image template_1_doll = LiveComposite(
    
    (1024,768),

    (0,0), "images/characters/template_1/hair/style_1/back_hair_[char_list[%s].hair].png"%curr_char, ####### This works great!

    (0,0), "images/characters/template_1/[char_list[%s].gender]_[char_list[%s].race]_head.png"%curr_char, ###### Not sure how to get this to work correctly.  Either need the same variable in both spots, or just two different variables

    )

I'm not sure what this is exactly called so I can't really do a search for it (%s isn't searchable as a 'thing').

Thanks for the help ahead of time!

- HB38
Last edited by HB38 on Tue Jan 12, 2016 10:12 pm, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: More variable 'fun' in images…

#2 Post by Alex »

When you have multiple %s in your code line, you need to specify a list of variables in appropriate order to fill them in, like

Code: Select all

"text_%s_%d_%s"%(string_var, data_var, another_string_var)

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: More variable 'fun' in images…

#3 Post by HB38 »

Alex wrote:When you have multiple %s in your code line, you need to specify a list of variables in appropriate order to fill them in, like

Code: Select all

"text_%s_%d_%s"%(string_var, data_var, another_string_var)
Ahh! Excellent - I was placing the ( on the left of the % when I tried using that.



You wouldn't happen to know what using %s to interpolate a variable is called?

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: More variable 'fun' in images…

#4 Post by HB38 »

Alright… I've run into an interesting issue now - it looks like everything is working great, but the images don't seem to be updating when I vary the variable in the game (they do change if I hard code the variable at the start, so I know the code there is solid). I'm thinking the LiveComposite doesn't 'recompile' constantly, and only when first called. How can I get it to refresh every time it's displayed?

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

Re: More variable 'fun' in images…

#5 Post by philat »

Yeah, when I saw this, it seemed odd that this would work properly. I already told you that I'm pretty sure you have to write out DynamicDisplayable by long hand.

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: More variable 'fun' in images…

#6 Post by HB38 »

philat wrote:Yeah, when I saw this, it seemed odd that this would work properly. I already told you that I'm pretty sure you have to write out DynamicDisplayable by long hand.
Pardon my ignorance, but what would that look like? Can I nest the Composite Inside it? Or do I convert the entire LiveComposite to a DynamicDisplayable?

Here's an example of a Live Composite I have:

Code: Select all

image template_1_doll = LiveComposite(
    
    (1024,768),

    (0,0), "images/characters/template_1/hair/style_1/hair_[char_list[%s].hair].png"%curr_char,

    (0,0), "images/characters/template_1/body/[char_list[%s].race].png"%curr_char,

    (0,0), "images/characters/template_1/[char_list[%s].gender]_[char_list[%s].race]_head.png"%(curr_char, curr_char),
    
    (0,0), ConditionSwitch(
        "char_list[%s].clothing == 'formal'"%curr_char, ConditionSwitch(
            "char_list[%s].eyes == 'blue'"%curr_char, "images/characters/template_1/clothes/formal_1_blue.png",
            "char_list[%s].eyes == 'brown'"%curr_char, "images/characters/template_1/clothes/formal_1_purple.png",
            "char_list[%s].eyes == 'green'"%curr_char, "images/characters/template_1/clothes/formal_1_green.png",
            ),
        "char_list[%s].clothing == 'casual'"%curr_char, ConditionSwitch(
            "char_list[%s].eyes == 'blue'"%curr_char, "images/characters/template_1/clothes/casual_1_blue.png",
            "char_list[%s].eyes == 'brown'"%curr_char, "images/characters/template_1/clothes/casual_1_purple.png",
            "char_list[%s].eyes == 'green'"%curr_char, "images/characters/template_1/clothes/casual_1_green.png",
            ),
      ),
I was looking at this post but it didn't seem to work correctly when I tried to implement it. Sorry I'm so dense on this stuff sometimes. :(

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: More variable 'fun' in images…

#7 Post by HB38 »

Ah HA! Bang on it enough (and get philat to PM you) and you figure it out:

Code: Select all


image template_1_doll = DynamicDisplayable(template_1_dollLC)

init 0 python:
    def template_1_dollLC(st,at):

        global curr_char

        return LiveComposite(
    
            (1024,768),

            (0,0), "images/characters/template_1/hair/style_1/hair_[char_list[%s].hair].png"%curr_char,

            (0,0), "images/characters/template_1/body/[char_list[%s].race].png"%curr_char,

            (0,0), "images/characters/template_1/[char_list[%s].gender]_[char_list[%s].race]_head.png"%(curr_char, curr_char),
            
            (0,0), ConditionSwitch(
                "char_list[%s].clothing == 'formal'"%curr_char, ConditionSwitch(
                    "char_list[%s].eyes == 'blue'"%curr_char, "images/characters/template_1/clothes/formal_1_blue.png",
                    "char_list[%s].eyes == 'brown'"%curr_char, "images/characters/template_1/clothes/formal_1_purple.png",
                    "char_list[%s].eyes == 'green'"%curr_char, "images/characters/template_1/clothes/formal_1_green.png",
                    ),
                "char_list[%s].clothing == 'casual'"%curr_char, ConditionSwitch(
                    "char_list[%s].eyes == 'blue'"%curr_char, "images/characters/template_1/clothes/casual_1_blue.png",
                    "char_list[%s].eyes == 'brown'"%curr_char, "images/characters/template_1/clothes/casual_1_purple.png",
                    "char_list[%s].eyes == 'green'"%curr_char, "images/characters/template_1/clothes/casual_1_green.png",
                    ),
              ),.1
I was missing that trailing .1… I'm not sure what it's for, but everyone is using it.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: [Sovled] DynamicDisplayables and Live Composites

#8 Post by PyTom »

The trailing .1 tells when Ren'Py should update the DD again, in case anything changed. It's called at least once per interaction, so you might be able to get away with None instead.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
HB38
Regular
Posts: 57
Joined: Sun Apr 27, 2014 2:14 pm
Contact:

Re: [Sovled] DynamicDisplayables and Live Composites

#9 Post by HB38 »

PyTom wrote:The trailing .1 tells when Ren'Py should update the DD again, in case anything changed. It's called at least once per interaction, so you might be able to get away with None instead.
Yeah, I monkeyed around with it a bit and figured it out. Thanks!

Post Reply

Who is online

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