[Solved] Efficiently coding a sprite change during dialogues

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
reismahnic
Newbie
Posts: 22
Joined: Tue May 08, 2018 3:31 pm
Projects: http://www.reismahnic.com
itch: side-group
Location: Portland, Oregon, USA
Contact:

[Solved] Efficiently coding a sprite change during dialogues

#1 Post by reismahnic »

Hello,
I'm working on a game that does not use side images, but features a lot of character expression changes.
Currently I've been handling this by manually changing each character's expressions each time the sprite needed to change.
However, I've now been adding talking sprites to each character, and this method is proving to be very cumbersome and hard to read.
As an example:

Code: Select all

show joseph Scene1NeutralTalking at left
joseph "It was lonely out there. Just had my sister."
show joseph Scene1Neutral at left
diane "Aunt Cheryl talks enough for four people."
show joseph Scene1HappyTalking at left
joseph "Heh! Isn't that the truth..."
show joseph Scene1Happy at left
As you can see, each time I need to change expressions I run a 'show' line of code, and that was working fine when the project had a smaller scope, but now that I'm having to show the character talking, these lines of code are becoming a bit ridiculous. I'm sure there's a smarter way to handle this that I'm just not privy to, but I'm hoping for a solution that allows me to not only change the character's sprite when they are talking but also change it back to the non-talking sprite when they are not.
Thank you for any assistance you can lend!
-Reis
Last edited by reismahnic on Sun Mar 15, 2020 6:54 pm, edited 1 time in total.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Efficiently coding a sprite change during dialogues

#2 Post by gas »

You can omit the 'at left' thing, as joseph is always joseph and keep his transform. The transform is relative to the tag (the first entry).

https://www.renpy.org/doc/html/displayi ... html#image

For expressions that last just one tense, you can simplify with say with image imaage attributes.
https://www.renpy.org/doc/html/dialogue ... attributes

Code: Select all

show john sad at left
j "I'm bored"
j @ happy "Now I'm happy"
j "I'm bored again"
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

reismahnic
Newbie
Posts: 22
Joined: Tue May 08, 2018 3:31 pm
Projects: http://www.reismahnic.com
itch: side-group
Location: Portland, Oregon, USA
Contact:

Re: Efficiently coding a sprite change during dialogues

#3 Post by reismahnic »

Hello, thanks for the response gas.
Sorry this response is coming in so late, I only have time to work on this project on weekends.
I greatly appreciate the help.

I'm struggling to get the image attributes code that you specified above working (also did read through the linked article).

I must be getting something small wrong, but here's some sample code of what I have right now.

Code: Select all

define joseph = Character("Joseph")
define diane = Character("Diane")
image joseph Scene1 = "js1neutralport"
image diane Scene1 = "ds1neutralport"
image diane Scene1T = "cs3neutralport"

diane "What do you think it was?"
diane @ diane Scene1T "You've never told me about this."
joseph "I used to avoid thinking about it."
In this example, no talk sprite appears for Diane even though I've specified to use her talking sprite, "cs3neutralport", temporarily in her second line of dialog.
Instead she just uses her neutral sprite for both lines.
I've also tried just

Code: Select all

diane @ Scene1T "You've never told me about this."
and this has also had no effect.

Thank you again for the assistance.

KField
Newbie
Posts: 3
Joined: Tue Feb 25, 2020 10:42 pm
Tumblr: chadteru
itch: katherine-field
Contact:

Re: Efficiently coding a sprite change during dialogues

#4 Post by KField »

Do you have to use the whole "Scene1" thing before an emotion? Because it seems to me like you could just put your image into a variable, and change that variable in the beginning of scene 2.

Code: Select all

default jhappy = "images/scene1josephhappy.png"
image joseph happy = "[jhappy]"
show joseph happy at left
joseph "This is scene 1."
hide joseph
$ jhappy = "images/scene2josephhappy.png"
show joseph happy at left
joseph "This is scene 2."
Something like this.

reismahnic
Newbie
Posts: 22
Joined: Tue May 08, 2018 3:31 pm
Projects: http://www.reismahnic.com
itch: side-group
Location: Portland, Oregon, USA
Contact:

Re: Efficiently coding a sprite change during dialogues

#5 Post by reismahnic »

I could play around with that, KField, but that aspect hasn't gotten in the way of the code length much and it makes it easier for me to track what's happening as each scene in the game jumps forward a significant amount of time (so each scene changes the character appearances significantly). Right now I want to focus on just getting the temporary talk sprite changes working, as Gas was explaining above. Unless there's something I'm not picking up on that you're trying to explain (apologies if so).

reismahnic
Newbie
Posts: 22
Joined: Tue May 08, 2018 3:31 pm
Projects: http://www.reismahnic.com
itch: side-group
Location: Portland, Oregon, USA
Contact:

Re: Efficiently coding a sprite change during dialogues

#6 Post by reismahnic »

So to be clear, I'm still looking for help with getting temporary sprite changes to work! So far I've had no luck with getting them to change during a single line of dialogue.

reismahnic
Newbie
Posts: 22
Joined: Tue May 08, 2018 3:31 pm
Projects: http://www.reismahnic.com
itch: side-group
Location: Portland, Oregon, USA
Contact:

Re: Efficiently coding a sprite change during dialogues

#7 Post by reismahnic »

Is... is it alright for me to bump this thread?
I'm still struggling to get my above code to work.
I've tried a number of variations based on what I'm seeing in other posts and none have worked yet based on my naming conventions. It seems clear that Gas' recommendation is the way to go for this, I just can't seem to actually get a Sprite change to occur for one line of dialog.
Thank you.

rames44
Veteran
Posts: 233
Joined: Sun May 29, 2016 4:38 pm
Contact:

Re: Efficiently coding a sprite change during dialogues

#8 Post by rames44 »

In some of the code above, your Character definitions were lacking the “image” attribute that would link the Character object to the image tag.

Code: Select all

joseph = Character(“Joseph”, image=“joseph”)
The variable name being the same as the image tag isn’t enough.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Efficiently coding a sprite change during dialogues

#9 Post by trooper6 »

Also, it isn’t good practice to name two different things the same name.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Efficiently coding a sprite change during dialogues

#10 Post by trooper6 »

I created a little project that works and shows how image tags work. You can run the project and see it in action.

Here's the code though:

Code: Select all

define j = Character("Joseph", image="joseph")
define d = Character("Diane", image="diane")

# The game starts here.

label start:

    show joseph at left
    show diane at right
    j "Hi! I'm Joseph. Starting off, I'll be shown with the image that has no tags."
    d "Me too!"
    j @wink "Let's talk about image tags! If you use @ then the tag is only visible
    while this line is happening. Once this line is over, I'll go back to the
    emotion I had before."
    d smile "That is very cool. I'm using a regular image tag...which means it'll
    stay around until I explicitly change it...notice Joseph isn't winking anymore."
    j "I'm not winking, that is true...but Diane is sill smiling."
    d "I am sill smiling...I'll keep smiling until someone changes my image tags."
    j surprise "Will you ever have another emotion?!"
    d angry "Of course, when I put in a new new image tag, it replaces the last one."
    j @wink "You look great when you are angry!"
    d "That isn't funny. Go back to your surprise look."
    j sad "Sorry."
    d -angry "I can also remove an image tag to bring me back to the base sprite."
    j -sad "I think that is everything you need to know! Bye!"

    return
Tester 8.zip
(1.74 MiB) Downloaded 17 times
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

reismahnic
Newbie
Posts: 22
Joined: Tue May 08, 2018 3:31 pm
Projects: http://www.reismahnic.com
itch: side-group
Location: Portland, Oregon, USA
Contact:

Re: Efficiently coding a sprite change during dialogues

#11 Post by reismahnic »

rames44 and trooper6, this is immensely helpful. trooper6 in particular, that small program was really insightful.
So the @ image attribute is actually directly targeting an image file name, not the 'image' attributes defined in code (as I was doing in my example above)?
I'm gonna probably have to basically recode the whole game to accommodate for this, but this is great to know.
So in my particular game each scene uses a completely different set of images for each character due to time jumps; does this mean I should be naming each CHARACTER by the scenes (example: josephScene1) rather than the images I'm trying to target (again, see above)?
Thank you again for this help.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Efficiently coding a sprite change during dialogues

#12 Post by trooper6 »

The image tags, whether you say @happy or happy, targets the image name as defined. But here is the thing, renpy automatically defines the images for you.
See here: https://www.renpy.org/doc/html/quickstart.html#images

So if you have a file named "josephS1 happy.png"
You can either not define it and it will automatically be named josephS1 with an image tag of happy.
Or you can hand define it: image josephS1 happy = "images/jospehS1 happy.png"

But you don't need to define it by hand because renpy does it automatically.

So what do you do about the fact that someone is going to change images over time...there are a couple options. You could define multiple characters, you could use dynamic images, or you could condition switch characters. There area lots of options. I can't expand the example with all the different options at this moment, because I have to do grading. But I can probably get around to it on Wednesday.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

reismahnic
Newbie
Posts: 22
Joined: Tue May 08, 2018 3:31 pm
Projects: http://www.reismahnic.com
itch: side-group
Location: Portland, Oregon, USA
Contact:

Re: Efficiently coding a sprite change during dialogues

#13 Post by reismahnic »

I'm working on refactoring all the code to make this work this week. I'm starting to get a firm grasp on how this works. Thank you for all the help, trooper6.
I would of COURSE love it if you do have a chance to provide further examples (they may still contain concepts that could help me), but if you don't I understand. I'm going to mark this thread solved in the meantime, because you did get me unstuck. Thanks again.

Post Reply

Who is online

Users browsing this forum: No registered users