Using Conditionals, or Variable to alter Image Defines?

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
Chendzeea
Newbie
Posts: 10
Joined: Fri May 18, 2018 8:05 pm
Contact:

Using Conditionals, or Variable to alter Image Defines?

#1 Post by Chendzeea »

I've a situation where a character has possible clothing swaps. Casual, Dress and Base outfits. I'm still learning the but I managed to use normal If statements to check which outfit to display but that only allows to check for 2

It seems to me that putting a new If statement anytime she changes expressions feels clumsy and excessive.

Example. at the moment I use Vicky_Expression_Dress, Vicky_Expression_Casual, ect ect. to call up which ever is needed.

I was hoping there was a way that I could use adjustable variable or condition to change the defined image to whichever is needed.
Here is the example code I was trying. I can get it to work with just a IF/Else statement but elifs are proving to be tricky.

if vcos == 1:
image vhappy = LiveComposite(
(580, 480),
(0, 0), "images/v-base2.png",
(0, 0), "images/v-smile.png")
image vdef = LiveComposite(
(580, 480),
(0, 0), "images/v-base2.png",
(0, 0), "images/v-neutral.png")
image vsad = LiveComposite(
(580, 480),
(0, 0), "images/v-base2.png",
(0, 0), "images/v-sad.png")
#Base
elif vcos == 2:
image vhappy = LiveComposite(
(580, 480),
(0, 0), "images/v-base3.png",
(0, 0), "images/v-smile.png")
image vdef = LiveComposite(
(580, 480),
(0, 0), "images/v-base3.png",
(0, 0), "images/v-neutral.png")
image vsad = LiveComposite(
(580, 480),
(0, 0), "images/v-base3.png",
(0, 0), "images/v-sad.png")
#Casual
else:
image vhappy = LiveComposite(
(580, 480),
(0, 0), "images/v-base.png",
(0, 0), "images/v-smile.png")
image vdef = LiveComposite(
(580, 480),
(0, 0), "images/v-base.png",
(0, 0), "images/v-neutral.png")
image vsad = LiveComposite(
(580, 480),
(0, 0), "images/v-base.png",
(0, 0), "images/v-sad.png")

User avatar
LateWhiteRabbit
Eileen-Class Veteran
Posts: 1867
Joined: Sat Jan 19, 2008 2:47 pm
Projects: The Space Between
Contact:

Re: Using Conditionals, or Variable to alter Image Defines?

#2 Post by LateWhiteRabbit »

Chendzeea wrote: Sun May 20, 2018 9:12 pm I've a situation where a character has possible clothing swaps. Casual, Dress and Base outfits. I'm still learning the but I managed to use normal If statements to check which outfit to display but that only allows to check for 2
If you are using the latest version of RenPy, you'll want to use Layered Images instead. PyTom just added it to make situations like this much easier. Much easier than LiveComposite.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Using Conditionals, or Variable to alter Image Defines?

#3 Post by kivik »

If you're not using layered images, you can also use Composite with variables:

Code: Select all

image eileen = Composite(
(580, 480),
(0, 0), "v-[eileen.base].png",
(0, 0), "v-[eileen.mood].png")
You'd need a character object called eileen in the above scenario, with attributes base and mood. Then just change eileen's mood by changing the attributes and the image will change.

Also you don't need /images in your image statements, unless your images are inside /game/images/images

Post Reply

Who is online

Users browsing this forum: Google [Bot]