Variable changing Talksprite

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
Kisses Fingers
Newbie
Posts: 2
Joined: Thu Mar 15, 2018 4:12 pm
Contact:

Variable changing Talksprite

#1 Post by Kisses Fingers »

Hi everyone! This is my first time using Ren'py, and I've run into a slight hurdle.

I wanted to write a script so that a character's sprite changes depending on a variable if the person playing the game makes any poor choices (Armour breaking, bruises appearing, etc). My first solution was to write

Code: Select all

show moon smile 0 at left
    if moon > 0:
        show moon smile 1 at left:
But I realised that this would be pretty inefficient every time I wanted to change the character's expression. I tried finding a solution myself and I thought putting something like this

Code: Select all

init:
    $ moon = 0
        
    image moon smile 0 = moon_smile_0.png
    image moon smile 1 = moon_smile_1.png
    image moon smile 2 = moon_smile_2.png
    image moon smile 3 = moon_smile_3.png
    image moon smile:
        choice (moon == 0):
            "moon smile 0"
        choice (moon == 1)
        choice (moon == 02:
            "moon smile 2"
            "moon smile 1"
        choice (moon == 3):
            "moon smile 3"
Could work, letting me just type "show moon smile" to get the main character in their current damaged state, but instead it only ever returns moon_smile_0.png.

I feel like there's something obvious I'm missing!! I've only started using Ren'py a few days ago though and have never really coded before. Any help

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Variable changing Talksprite

#2 Post by Imperf3kt »

You want to use either ConditionSwitch or LiveComposite
https://www.renpy.org/doc/html/displayables.html
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Kisses Fingers
Newbie
Posts: 2
Joined: Thu Mar 15, 2018 4:12 pm
Contact:

Re: Variable changing Talksprite

#3 Post by Kisses Fingers »

Oh, thanks for the advice!! It isn't particularly elegant, but I used this for my code

Code: Select all

image moon smile = ConditionSwitch(
    "moon == 1", "moon_smile_1.png",
    "moon == 2", "moon_smile_1.png",
    "moon == 3", "moon_smile_3.png",
    "True", "moon_smile_0.png")
That seems to have pulled it all together though. Thank you!!

Post Reply

Who is online

Users browsing this forum: GoldenGob, Google [Bot], SelLi