Layeredimage, hiding hair only if hood's equipped.

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
Exiscoming
Regular
Posts: 132
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Layeredimage, hiding hair only if hood's equipped.

#1 Post by Exiscoming »

I'm making a game where the characters can switch hairstyles and outfits. Some of them have a hood. How do I hide the hair ONLY when a hood is equipped?

Code: Select all

layeredimage character1:
	always:
		"baseModel.png"
	if hair == 1:
		"hair1.png"
	elif hair == 2:
		"hair2.png"
	elif hood == True:
		# Hair should hide here.
At first I figured I'd wrap it all into 1 big IF statement:

Code: Select all

layeredimage character1:
	always:
		"baseModel.png"
	if hood == False:
		if hair == 1:
			"hair1.png"
		elif hair == 2:
			"hair2.png"
But layeredimages don't accepted indented if statements. So the only solution would be:

Code: Select all

if hair == 1 and hood == False:
if hair == 2 and hood == False:
etc.
I'm hoping for a bit more elegant solution. Does anyone have any suggestions?

strayerror
Regular
Posts: 159
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Layeredimage, hiding hair only if hood's equipped.

#2 Post by strayerror »

Not tested but iirc you can do something like this, although it does mean you'd have to use attributes rather than rely on an external variable.

Code: Select all

layeredimage character1:
    always:
        'baseModel.png'

    group hair only_if 'nohood':
        attribute hair1 default 'hair1.png'
        attribute hair2 'hair2.png'

    group hood:
        attribute nohood default null
        attribute hood1 'hood1.png'

label start:
    show character1
    'using implied hair1'
    show character1 hair2
    'using explicit hair2'
    show character1 hood1
    'using explicit hood1, hair group hidden'

strayerror
Regular
Posts: 159
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: Layeredimage, hiding hair only if hood's equipped.

#3 Post by strayerror »

Or for super simple, maybe you get away with simply reordering your if statement?

Code: Select all

layeredimage character1:
	always:
		"baseModel.png"
	if hood == True:
		null # or hood image
	elif hair == 1:
		"hair1.png"
	elif hair == 2:
		"hair2.png"

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

Re: Layeredimage, hiding hair only if hood's equipped.

#4 Post by philat »

I don't really use layeredimages (never had a need), so take what I'm saying here with a grain of salt, but.

1. This thread looks interesting for more advanced stuff, see if that works. viewtopic.php?f=8&t=56250

2. From what I can tell, layeredimage should be able to take DDs rather than just straight files, so you could theoretically do this (which seems to work based on barebones tests in a clean project, but obvs I can't test with your files).

Code: Select all

layeredimage character1:
    always:
        "baseModel.png"
    if not hood: # same as if hood == False
        "hair[hair].png"

Exiscoming
Regular
Posts: 132
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Re: Layeredimage, hiding hair only if hood's equipped. [Solved]

#5 Post by Exiscoming »

Heya guys,

Sorry for the late reply. Got it fixed!
So I chose to remove the hood variable (cause it would cause the model's hair to unequip even when wearing a different hat).
Instead I did this:

Code: Select all

if hat == 9:
	"models/green/hair/noHair.png"	# empty png
elif hair == 1:
	"hair1.png"
Seeing as it goes by the if statement first (and sees it's true) it never goes past the elif statement afterwards.
Thank you guys so much, I wouldn't have thought of this without you!

Post Reply

Who is online

Users browsing this forum: Baidu [Spider]