Calling Image Attribute by Variable

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
gimyosan
Newbie
Posts: 2
Joined: Sun Jan 05, 2020 3:50 am
Tumblr: gimyosan
Contact:

Calling Image Attribute by Variable

#1 Post by gimyosan »

I'm trying to implement a semi-randomized outfit system where a character is dressed consistently for a period of time. I'm currently using a layered image system for the clothing sprites and it works great, but I'm a bit stuck on how to approach the randomizer system. I was thinking of something kind of like this:

Code: Select all

$ bottom = renpy.random.choice(["pants"])
$ top = renpy.random.choice(["collar", "longsleeve", "sweater"])

show npc armscrossed happy [bottom] [top]_armscrossed  
But that doesn't work due to the way layer image attributes are called. Does anyone have tips on how to tackle this problem?

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Calling Image Attribute by Variable

#2 Post by gas »

Layeredimages can use variables to set a picture for that layer, so you can use a renpy.random to randomize what to show.
Finally, the if statement adds a layer that selects between displayables using a Python statement. This is evaluated constantly, and the first condition that evaluates to true is the one that's displayed.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Post Reply

Who is online

Users browsing this forum: AWizardWithWords, Ocelot