[SOLVED] What is the best way to create a condition switch for all attributes in a layeredimage group?

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
heartfragment
Regular
Posts: 109
Joined: Tue Nov 10, 2015 12:10 am
Projects: Heart Fragment
Tumblr: heartfragment
itch: heartfragment
Contact:

[SOLVED] What is the best way to create a condition switch for all attributes in a layeredimage group?

#1 Post by heartfragment »

Apologies in advance if this is a silly question and I'm missing something obvious!

The issue:
I have my sprites defined as layered images. However, there is an option in the settings that changes sprite style that can be toggled at any time. In order to make that work with the attributes of the layered image, I need to make a condition switch available for all attributes in a group.

I previously had my images defined as livecomposites where the two styles were separate sprites, and then used a separate image for each sprite with a condition switch to switch between them. This worked perfectly, but it was limiting because I couldn't combine all possible sprite expressions without defining like 100 different images.

I tried to do the same thing with the layeredimages - defined the two styles are separate layered images and then a separate condition switch image to choose which style is used. Unfortunately this didn't work, because the conditionswitch didn't allow me to actually switch between the image's attributes. I tried using a layeredimageproxy to see if that might allow me to do what I need but that was also unsuccessful.

I know that you can use "if" statements within layeredimages but only for one thing at a time and not the actual attributes.

Other things I've tried:
- defining every attribute for both styles on their own and then making a conditionswitch for every attribute. This did not work because for some reason the layered image would show all layers at once if I tried to switch styles. It worked fine by default, but the moment the button was pressed all of a sudden the sprite had 10 different eyes and mouths and eyebrows on top of each other
- putting an "if/else" statement before each attribute when writing them out in the layeredimage
- putting an if/else statement before each group in the layeredimage

I'm sure there's probably some really easy solution that I'm missing but since I've been struggling with this for a few weeks now and still haven't had any luck getting a solution working, I figured I'd turn to the forums. :')
Last edited by heartfragment on Sat Oct 10, 2020 7:04 pm, edited 1 time in total.
Published Project:
Image

User avatar
heartfragment
Regular
Posts: 109
Joined: Tue Nov 10, 2015 12:10 am
Projects: Heart Fragment
Tumblr: heartfragment
itch: heartfragment
Contact:

Re: What is the best way to create a condition switch for all attributes in a layeredimage group?

#2 Post by heartfragment »

If anyone has any recommendations I would definitely still appreciate it. :) I've had a few moments where I think I've figured out a solution but nothing ends up working properly.
Published Project:
Image

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: What is the best way to create a condition switch for all attributes in a layeredimage group?

#3 Post by Jackkel Dragon »

To begin with, maybe what I went over in this thread can help in some way: link

Secondly, to my understanding, layered image proxies are for using the same layered image for multiple displayables at once. For instance, a scene with a clone/duplicate of a character can use the same basic layered image as the character they are a clone of, but both can be displayed at the same time. I haven't tried it in a while, but I assume it would be similar to "show yue at left as yue_clone", which uses the "yue" image but gives it the tag "yue_clone". (With proxies probably being easier to use, I'll bet.)

As for the situation at hand, you may have to use filename/imagename interpolation to get the images defined in a low-code manner, as shown in the other thread. For instance, you could end up with something like this:

Code: Select all

default persistent.charname_style = "monochrome"
layeredimage charname:
	## lower layers
	
	## outfit layer as sample
	group outfit: ## image names from auto are "charname_outfit_[attribute]"
		attribute dress: ## defaults to "charname_outfit_dress" when group is auto
			"charname_outfit_[persistent.charname_style]_dress" ## if the variable is set to "monochrome", then the final image name is "charname_outfit_monochrome_dress"
	
	## higher layers
I think there's a way to programmatically do this where you don't have to define each attribute manually, but I would need to test the code before I was certain it could work. The above probably should work, but requires you to define every attribute that can be affected by the variable manually.

(I'm so glad I took extra time to proofread this before I sent it, because I almost linked to the wrong thread and described the wrong method. I may not be as awake as I thought...)
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
heartfragment
Regular
Posts: 109
Joined: Tue Nov 10, 2015 12:10 am
Projects: Heart Fragment
Tumblr: heartfragment
itch: heartfragment
Contact:

Re: What is the best way to create a condition switch for all attributes in a layeredimage group?

#4 Post by heartfragment »

Jackkel Dragon wrote: Sat Oct 10, 2020 3:51 pm To begin with, maybe what I went over in this thread can help in some way: link.......
This worked perfectly! Thank you so much, you're an absolute lifesaver. :D
Published Project:
Image

Post Reply

Who is online

Users browsing this forum: Ocelot