[solved] Varying layered images with variables and conditionals

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
Phantomask
Newbie
Posts: 2
Joined: Mon Sep 15, 2014 1:21 pm
Contact:

[solved] Varying layered images with variables and conditionals

#1 Post by Phantomask » Thu Oct 13, 2022 2:04 pm

Hello everybody.

Whilst having no coding background whatsover, I have been a ren’py vn reader for quite some time now, hence the irrepressible urge to try and make one myself :mrgreen:

However it seems my loosy dabbling hit a rock.

What I wanted to achieve was making my characters’ clothing change depending on some variable, whilst using layered image for my sprites.

Here is what I tried, and which didn’t work, causing a « end of line expected » error centered on the « if » :

Attempt number 1:

Code: Select all

layeredimage character:
    group clothes:
        attribute work:
            "character_clothes_work"
        attribute leisure:
            if spentsundaytogether:
                "character_clothes_casual"
            else:
                "character_clothes_formal"
    group face auto
Attempt number 2:

Code: Select all

layeredimage character:
    group clothes:
        attribute work:
            "character_clothes_work"
        if spentsundaytogether:
                attribute leisure:
                    "character_clothes_casual"
        else:
                attribute leisure:
                    "character_clothes_formal"
    group face auto
Any advice please ?
(I haven’t found this with a forum search, but please excuse me if it had already been answered on a former topic)

Thanks in advance.
Last edited by Phantomask on Thu Oct 13, 2022 8:24 pm, edited 1 time in total.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Varying layered images with variables and conditionals

#2 Post by _ticlock_ » Thu Oct 13, 2022 6:00 pm

if statements do not work inside group or attribute

There are two things you can do in your example:

1) Use a variable and substitution:

Code: Select all

default var = "formal"

layeredimage character:
    group clothes:
        attribute work:
            "character_clothes_work"
        attribute leisure:
            "character_clothes_[var]"
    group face auto

#Somewhere in the game where spentsundaytogether is defined
label spentsundaytogether:
    $ var = "casual"
2) Use ConditionSwitch:

Code: Select all

layeredimage character:
    group clothes:
        attribute work:
            "character_clothes_work"
        attribute leisure:
           ConditionSwitch(
                "spentsundaytogether", "character_clothes_casual",
                "True","character_clothes_formal",
                )
    group face auto

Phantomask
Newbie
Posts: 2
Joined: Mon Sep 15, 2014 1:21 pm
Contact:

Re: Varying layered images with variables and conditionals

#3 Post by Phantomask » Thu Oct 13, 2022 8:23 pm

Well that was fast, thank you a lot !

ConditionSwitch is indeed just what I needed to learn. :)

Thanks again !

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]