Page 1 of 1

[Solved] Efficiently coding a sprite change during dialogues

Posted: Sat Feb 22, 2020 6:54 pm
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

Re: Efficiently coding a sprite change during dialogues

Posted: Sat Feb 22, 2020 9:44 pm
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"

Re: Efficiently coding a sprite change during dialogues

Posted: Sat Feb 29, 2020 7:47 pm
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.

Re: Efficiently coding a sprite change during dialogues

Posted: Sat Feb 29, 2020 10:29 pm
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.

Re: Efficiently coding a sprite change during dialogues

Posted: Sun Mar 01, 2020 1:11 am
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).

Re: Efficiently coding a sprite change during dialogues

Posted: Mon Mar 02, 2020 5:55 pm
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.

Re: Efficiently coding a sprite change during dialogues

Posted: Mon Mar 09, 2020 8:45 am
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.

Re: Efficiently coding a sprite change during dialogues

Posted: Mon Mar 09, 2020 12:02 pm
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.

Re: Efficiently coding a sprite change during dialogues

Posted: Mon Mar 09, 2020 8:35 pm
by trooper6
Also, it isn’t good practice to name two different things the same name.

Re: Efficiently coding a sprite change during dialogues

Posted: Mon Mar 09, 2020 9:50 pm
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 2 times

Re: Efficiently coding a sprite change during dialogues

Posted: Mon Mar 09, 2020 11:27 pm
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.

Re: Efficiently coding a sprite change during dialogues

Posted: Tue Mar 10, 2020 1:42 am
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.

Re: Efficiently coding a sprite change during dialogues

Posted: Sun Mar 15, 2020 6:53 pm
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.