Dynamically passing variables as attributes to LayeredImage

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
Vitalis
Newbie
Posts: 8
Joined: Wed Nov 24, 2021 5:05 pm
Contact:

Dynamically passing variables as attributes to LayeredImage

#1 Post by Vitalis »

I'm trying to make a paperdoll system for a customizable character, already did some experimenting with Composite, but LayeredImage seems simpler and more elegant in many ways so I decided to try that. But I've hit a snag: I can't figure out how to make the image dynamically change attributes via changing variables.

Here's an example snippet of what I've been doing:

Code: Select all

init python:
 skintones = ["light", "tan"]
 skintone = 0
 skinLen = len(skintones) - 1
 
layeredimage char:

 group skintone:
  attribute light default
  attribute tan

screen dressup():
  
 fixed:
  text "Skintone"
  imagebutton idle "gui/arrowL.png" action Return("prevSkintone")
  imagebutton idle "gui/arrowR.png" action Return("nextSkintone") xoffset 150

label start:
 show char  
 
 show screen dressup
 jump dressup

label dressup:
 $ skinName = skintones[skintone]
 show char [skinName]
 
 $ picked = ui.interact()
 if picked == "nextSkintone":
  if skintone < skinLen:
   $ skintone += 1
  
 if picked == "prevSkintone":
  if skintone > 0:
   $ skintone -= 1

 jump dressup
This results in the character being properly drawn and the variables "skintone" and "skinName" correctly changing when clicking the button. However, with each click a message appears on the screen: "char unknown attributes: light" and "char unknown attributes: tan". So the variable is correctly passed to the char LayeredImage but for some reason it doesn't recognize it as an attribute. I tried formulating it in different ways, but nothing seems to work.

What am I doing wrong? Should I be using LayeredImage for this at all?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Dynamically passing variables as attributes to LayeredImage

#2 Post by Ocelot »

show char [skinName] does not do what you think it does. It tries to access char variable as a container, which it isn't (exactrly like you accessed skintones on previous line). If you want to provide image attributes contained in a variable, you need to use Python equivalent of show statement:

Code: Select all

$ renpy.show( "char {0}".format(skinName) )
< < insert Rick Cook quote here > >

Vitalis
Newbie
Posts: 8
Joined: Wed Nov 24, 2021 5:05 pm
Contact:

Re: Dynamically passing variables as attributes to LayeredImage

#3 Post by Vitalis »

Thank you, this works as expected! I experimented a bit more and I'm able to switch attributes fairly reliably.

I have a couple more questions now :

1. Is it possible to programmatically define a LayeredImage? E.g. taking a list or dict of variables and turning them into groups and attributes? I've been trying to do that with sth like

Code: Select all

image char = LayeredImage("char_skintone_light", "char_skintone_tan")
but it just appears as a blank character outline. I'm probably misunderstanding something really basic again. :x

Adding attributes to an already existing LayeredImage would also be great.

2. I've been trying to make each change come with a dissolve effect but I don't know how to achieve that. LayeredImage doesn't take the "with Dissolve" statement like Composite does, I know there is config.say_attribute_transition_layer but it seems it's useless when I'm not using any say statements, just show.

Thank you in advance!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot]