Changing image based on who is speaking [SOLVED]

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
Jojobean
Newbie
Posts: 10
Joined: Sun Jun 21, 2015 12:59 am
Contact:

Changing image based on who is speaking [SOLVED]

#1 Post by Jojobean » Wed Sep 23, 2015 12:15 am

When a character is speaking, I want to display a different image than when they are not. Currently, I've been doing something like this:

Code: Select all

show queen grey
"The queen steps forward to greet you."
show queen
q "Hello child."
show queen grey
n "Hello, your majesty."
Eventually, I thought there must be an easier way to do this, especially when there are multiple characters in a scene. Is there a way to use a condition switch based on the character is speaking to change the displayed image? This would save me so much time!

Thanks so much!
Last edited by Jojobean on Wed Sep 23, 2015 8:28 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 15316
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Changing image based on who is speaking

#2 Post by PyTom » Wed Sep 23, 2015 12:43 am

It's available as _last_say_who. This is the unevaluated string, so you'll have:

Code: Select all

e "Hello, world." # _last_say_who == "e"
"Hello, Eileen." # _last_say_who == None
You should be able to use this in ConditionSwitch.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Jojobean
Newbie
Posts: 10
Joined: Sun Jun 21, 2015 12:59 am
Contact:

Re: Changing image based on who is speaking

#3 Post by Jojobean » Wed Sep 23, 2015 8:28 pm

Thank you so much! That did exactly what I needed!!

User avatar
Jojobean
Newbie
Posts: 10
Joined: Sun Jun 21, 2015 12:59 am
Contact:

Re: Changing image based on who is speaking [SOLVED]

#4 Post by Jojobean » Sun Nov 08, 2015 3:29 pm

Here's the final code:

Code: Select all

define q = Character ('Queen Isabel')
Start by defining your character.

Code: Select all

 image queen =  ConditionSwitch(
            "_last_say_who == 'q'", "images/queen1.png",
            "not _last_say_who == 'q'", "images/queengrey.png")
Next use a condition switch with the variable _last_say_who . I guess Ren'py uses this to keep track of who is talking. Set it to equal the abbreviated version of the characters name.

Code: Select all

 q "hello there"
"chicken is delicious"
q "I hope it works!" 
The character should turn into the first image when she is speaking and the second image when she is not.

I hope this helps!

Post Reply

Who is online

Users browsing this forum: Imperf3kt, isobellesophia