[SOLVED] Persistent Image For a Character Beyond Just (Label) Scenes

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
Dimorphodon
Newbie
Posts: 12
Joined: Sat Mar 21, 2020 9:36 pm
Contact:

[SOLVED] Persistent Image For a Character Beyond Just (Label) Scenes

#1 Post by Dimorphodon »

INTRO (you can skip to the question)It seems there should be an easy way to do this; I read questions/answers on the forums and I looked through the Ren'Py guide. (Most of my research and attempts were made over 11 months ago, and when I looked at it with 'new eyes'--no luck). If the answer is out there, then I did not understand it or I missed it. I finally registered to ask this question and a few others. Please advise.

The Question I want to set a common image for a character in a story that pops up every time the character speaks--a default image. It can change and swap out as needed, but I want a basic common image. Essentially, I want to tie the image variable to the character tag. Every time one character speaks, the same image should pop up in exactly the same location.

I know how to manually change an image by adding code each time a character speaks. But manually coding in the same image link each time the same character speaks seems like an enormous amount of work and it seems there must be a better way.

The Ren'Py guide seemed to suggest I can, for each scene (label), set an image that will show until the next (jump)...but I have many jumps and menus in my game, so that would not save much time.

Any ideas?
Last edited by Dimorphodon on Thu Mar 26, 2020 10:44 pm, edited 1 time in total.

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

Re: Persistent Image For a Character Beyond Just (Label) Scenes

#2 Post by gas »

From your words, it look like you misspelled the thing. You don't have to show the character for each line spoken.
So, for example...

Code: Select all

show eileen
e "I'm talking..."
e "...and there too"
e "and there too again"
Eileen sprite is shown all the dialogue lines until you actively hide it. So it's not exactly a great effort.

Using TAGS you can simplify your life even more.
Let's define the character this way... (with the premise you have "eileen_normal.png", "eileen_sad.png" and "eileen_happy.png" in your IMAGES folder).

Code: Select all

define e = Character("Eileen", image = "eileen")
show eileen normal
e "I'm normal"
e sad "Now I'm shown sad"
e "I'm sad again..."
e @ happy "I'm happy for one tense only thanks to @!"
e "Now I'm back to sadness, the previous tag, even when not quoting it"
e normal "Back to normal here and onward"
As you can see it's quite immediate to show different sprites for a single character not using the standard 'show' thing again and again.

As a last note, the AT parameter, once applied, stay applied until you hide and reshow the same image OR use a scene statement.
So you can simply define an AT transform and apply it.

Code: Select all

show eileen at left
e "I'm at left..."
show eileen sad
e "While not specified, I'm at left again..."
All of this guarantee that you can apply a lot of possible exceptions without hardocding the display of sprites.
So, for example, the only single 2 or 3 cases when you want for something different to happen (like your character flipped on the right side or on a different position for the lasting of a single scene... who knows).
With power come responsibility.
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

Dimorphodon
Newbie
Posts: 12
Joined: Sat Mar 21, 2020 9:36 pm
Contact:

Re: Persistent Image For a Character Beyond Just (Label) Scenes

#3 Post by Dimorphodon »

First- Thank you for taking the time to write a thorough response!
Second- I previously have tried setting up tags as per the official guides; however, despite trying it again with the enlightenment of your clear instructions, I still cannot get it to work. After seeing your suggestion, I tried again in my program. When that did not work, I set up a simplified test environment. Below is the test code.

Every time a scene change or jump occurs, the Eileen image disappears.

I see you indicate that "scene" will destroy persistence (thank you for that information--that is concerning and disappointing, but I suppose it is what we have to work with.

However, also after "jumps", the Eileen image does not have persistence.

What I had been hoping was that the "e" would always default to the image despite any jumps or scene changes--it seems like that is not possible. My game already has hundreds of jumps and could potentially have many more.

In the below example: my understanding and hope is that label "Test 1" should still show the Eileen image; however, it does not.

Code: Select all

define e = Character("Eileen", image="eileen")
# image side eileen = "eileen" # This works but not implementing it here because it also writes over the text box. https://www.renpy.org/doc/html/side_image.html (Leaving Room/Customization seems to explain how to fix that problem but that is extremely complex; advanced.)
define n = Character("Narrator")

#omitted some code in-between

label a1:
scene 1_one
n "Lorem ipsum."

scene 1_two
show eileen at left
e "Sin dolor est."

scene 1_three
e "testing"

scene 1_four
n "testing four."

scene 1_five
e "testing"

scene 1_six
show eileen at left
e "I'm normal"
e "Now I'm shown sad"
e "I'm sad again..."
jump test1

label test1:
scene 1_seven
e "testing eileen"

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

Re: Persistent Image For a Character Beyond Just (Label) Scenes

#4 Post by gas »

Ah, ok, sorry.
SCENE statement erase completely what's on the screen. It's usually made for what in movies are change of locations.
It erase characters and restart the tag queue.
That's something you can't avoid in any possible way (if not by messing with layers, but this will be longer than retyping show all the time).

What you want to do is to change the background image alone - that's usually one of the effect of the scene statement, but not the only one as said.
You can use instead SHOW like any other picture.
If all background images have the same starting tag, like

bg alley
bg garden

you can do something like this:

Code: Select all

show bg alley # the fullsized picture
show eileen
show lucy
e "A dialogue line"
show bg garden
e "And now the same, but above a garden picture"
MIND THAT'S NOT the standard renpy use and could have drawbacks I dunno.
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

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: Persistent Image For a Character Beyond Just (Label) Scenes

#5 Post by trooper6 »

I suppose I'd have to ask...do you actually need thousands of scenes? Or might your code be able to be optimized? I've seen a lot of Renpy games...and I've not seen one with thousands of scenes. Do those six scene_1, really need to be different scenes? Might there be ways to do what you want in an easier way? For example, I have a little game that has lots of different "camera angle" changes...but those aren't done by lots of different scenes, but by using ATL zoom in on one part of the bg, then move to a different part of the bg.

So what actually is happening in your code?
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

Dimorphodon
Newbie
Posts: 12
Joined: Sat Mar 21, 2020 9:36 pm
Contact:

Re: Persistent Image For a Character Beyond Just (Label) Scenes

#6 Post by Dimorphodon »

Gas

Thank you; that moved closer to solving my issue, however there is still a problem.

Here is some code to show what is happening.

The "e" image persists UNTIL the "n" tag comes up, but then the next "e" reference does NOT call back the image. Is that expected? I had hoped that by using the "shows" instead of "scenes" the e images would not be re-set-- and it seems they are fine... until another person tag speaks, which is a fatal problem.

Further, the second "show eileen at left" option won't show the eileen image again? This is an unexpected outcome.

In the codeblock below I have tried it with and without the transform section.

Code: Select all

define e = Character("Eileen", image="eileen")
define n = Character("Narrator")

#This causes the side image to slide in and out when the character associated with that image changes:
transform change_transform(old, new):
    contains:
        old
        yalign 1.0
        xpos 0.0 xanchor 0.0
        linear 0.2 xanchor 1.0
    contains:
        new
        yalign 1.0
        xpos 0.0 xanchor 1.0
        linear 0.2 xanchor 0.0
define config.side_image_change_transform = change_transform

label start:

OMITTED CODE

label a1:
scene 1_a
n "xxxxxxxx."

show 1_b
show eileen at left
e "Ie."

show 1_d
e "testing"

show 1_c
n "xxxxxx."

show 1_d
e "testing2"
show eileen at left
e "no worries"
n "yes worry"
e "aha"

show 1_a
e "I'm normal"
e "Now I'm shown sad"
e "I'm sad again..."
jump test1

label test1:
scene 1_britain
e "testing eileen"

return
MIND THAT'S NOT the standard renpy use and could have drawbacks I dunno.
- I am curious... Why is that not the standard ren'py use?

- If what I am suggesting is really strange, then what do most people do?

Also, any thoughts about why the image is not showing for "e" after the jump to a new label? Is there a way to make the image persistent after jumps? Or, do I need to re-define the image each time after a jump?
Last edited by Dimorphodon on Tue Mar 24, 2020 10:06 pm, edited 1 time in total.

Dimorphodon
Newbie
Posts: 12
Joined: Sat Mar 21, 2020 9:36 pm
Contact:

Re: Persistent Image For a Character Beyond Just (Label) Scenes

#7 Post by Dimorphodon »

trooper6 wrote: Tue Mar 24, 2020 5:25 am I suppose I'd have to ask...do you actually need thousands of scenes? Or might your code be able to be optimized? I've seen a lot of Renpy games...and I've not seen one with thousands of scenes. Do those six scene_1, really need to be different scenes? Might there be ways to do what you want in an easier way? For example, I have a little game that has lots of different "camera angle" changes...but those aren't done by lots of different scenes, but by using ATL zoom in on one part of the bg, then move to a different part of the bg.

So what actually is happening in your code?
Thank you trooper6; it is an honor to hear from you. I have referenced some of your posts over the past years to get me through some tricky coding questions!

1. My real problem is the image tags do not persist across jumps- I have many, many jumps usually occurring after just a couple lines of text, so I had hoped I could have a persistent image show for each character (popping up only when they speak) rather than writing a "show" tag each time per character after every jump.

2. The example code above was meant to demonstrate that both the scenes and the jumps ended the persistent images. The scene problem is more minor with respect to the game project I have been working on that is very close to a public demo--but the demo game has many jumps and it seemed non-optimal coding to constantly have to repeat the show image command. The scene problem was more of an issue with a not-as-serious side project I was working on to test some things out; the side project has tons of images and was intended to work like a choose-your-adventure picture book.

3. No, in this situation, camera angle zooms would not work. I appreciate the idea though; maybe in another situation it would be useful!

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Persistent Image For a Character Beyond Just (Label) Scenes

#8 Post by philat »

Just to be clear, the plan is that 1. there is only ever one image associated with a speaker showing (i.e., it is not a situation where there are two speaking characters showing side by side on the screen), and 2. you want to automatically switch out the image to show whoever is speaking?

Code: Select all

screen say(who, what, sidex=0.5, sidey=1.0):
    style_prefix "say"

    ## moved this from bottom -- puts the sideimage behind the textbox
    if not renpy.variant("small"):
        add SideImage() xalign sidex yalign sidey # centered by default but changeable

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        text what id "what"


    # ## If there's a side image, display it above the text. Do not display on the
    # ## phone variant - there's no room.
    # if not renpy.variant("small"):
    #     add SideImage() xalign 0.0 yalign 1.0

define anne = Character("Anne", image="anne")
define beth = Character("Beth", image="beth")
image side anne = Solid("#F00", xysize=(500,500))
image side anne happy = Solid("#F006", xysize=(500,500))
image side beth = Solid("#FF0", xysize=(500,500))
image side beth happy = Solid("#FF06", xysize=(500,500))


label start:
    scene grey
    anne "1"
    beth "2"
    jump jumptest1

label jumptest1:
    scene black
    anne "3 afterjump"
    anne @happy "4 happy"
    anne "5" (show_sidex=0.0) # move sideimage to xalign 0.0 temporarily
    beth @happy "6 happy"
    beth "8"
    return

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: Persistent Image For a Character Beyond Just (Label) Scenes

#9 Post by trooper6 »

Dimorphodon wrote: Tue Mar 24, 2020 10:05 pm
Thank you trooper6; it is an honor to hear from you. I have referenced some of your posts over the past years to get me through some tricky coding questions!

1. My real problem is the image tags do not persist across jumps- I have many, many jumps usually occurring after just a couple lines of text, so I had hoped I could have a persistent image show for each character (popping up only when they speak) rather than writing a "show" tag each time per character after every jump.

2. The example code above was meant to demonstrate that both the scenes and the jumps ended the persistent images. The scene problem is more minor with respect to the game project I have been working on that is very close to a public demo--but the demo game has many jumps and it seemed non-optimal coding to constantly have to repeat the show image command. The scene problem was more of an issue with a not-as-serious side project I was working on to test some things out; the side project has tons of images and was intended to work like a choose-your-adventure picture book.

3. No, in this situation, camera angle zooms would not work. I appreciate the idea though; maybe in another situation it would be useful!
Thank you for the compliment!
About 1: image tags aren't cleared with jumps, only with new scene commands and you don't have to have a scene command with new labels....you only need a new scene command if you are actually in a new scene.

About 2: I still encourage you to think about optimizing those labels a bit. Perhaps put some more thing in menus rather than putting them in their own labels.

Anyhow, I put a project together for you that shows how images aren't cleared just after a jump.

Code: Select all

# The script of the game goes in this file.

# Declare characters used by this game. The color argument colorizes the
# name of the character.

define d = Character("Diane", image="diane_1")
define j = Character("Joseph", image="joseph_1")

# The game starts here.

label start():
    scene bg underpassday

    show diane_1 at left
    show joseph_1 at right

    d "What a lovely scene we are in"
    j surprise "Yep, it is lovely. But what is that?!"

    jump scene2

    return

label scene2():
    d "Is everything cleared?"
    j "It isn't, becasue we haven't given a new scene command. Jumping doesn't clere, just scene commands."
    d "And we don't have to declare a new scene just becuase we jump or call."
    j "Nope and our image tags are still in effect, too."

    d "I do want to point out something about more optimized code."
    j "What's that?"

    d smile "Sometimes people think they need to jump to everything, like so."
    menu:
        "How are you feeling Joe"
        "Great":
            jump great1
        "So So":
            jump soso1
        "Terrible":
            jump terrible1

label great1():
    j smile "I'm doing great!"
    d "Awesome!"
    jump afterfeeling1

label soso1():
    j "I'm okay, so so."
    d "Could be be worse though!"
    jump afterfeeling1

label terrible1():
    j sad "I'm feeling awful"
    d sad "I'm sorry to hear that."
    jump afterfeeling1

label afterfeeling1():
    d "So to get through that, we have 5 labels...but threre are ways to optimize that some."
    j surprise "Like how?"
    d "Something like this...just put more things in the the menu choices!"
    menu:
        "How are you feeling Joe?"
        "Great":
            j "I'm doing great!"
            d "Awesome!"
        "So So":
            j "I'm okay, so so."
            d "Could be be worse though!"
        "Terrible":
            j "I'm feeling awful"
            d "I'm sorry to hear that."

    d "And we are done...and we did all of that in one label. You can put a lot in those menus."
    j "And there are other ways to optimze as well."
    d "But we should be done...talk to you later!"

    return

Attachments
Tester 9.zip
(3.19 MiB) Downloaded 15 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

Dimorphodon
Newbie
Posts: 12
Joined: Sat Mar 21, 2020 9:36 pm
Contact:

Re: Persistent Image For a Character Beyond Just (Label) Scenes

#10 Post by Dimorphodon »

Philat-
Just to be clear, the plan is that 1. there is only ever one image associated with a speaker showing (i.e., it is not a situation where there are two speaking characters showing side by side on the screen), and 2. you want to automatically switch out the image to show whoever is speaking?
Thank you for the response!

The plan was that, for the most part, yes, one character per line but occasionally, two character or more characters may show, like in Trooper6's example where an image is shown on the left and another is shown on the right.

Re 2. My thought in using the switch out code was it would make the image changes slide and look seamless.

The example you provide is a little beyond me at the moment--I think you are trying to show me a better way to do image slides and to not have character images overwritten by backgrounds--is that correct?

Once I start plugging more images into projects it hopefully will make more sense to me.

Trooper6 -

1. Thank you; that works!
"image tags aren't cleared with jumps, only with new scene commands and you don't have to have a scene command with new labels....you only need a new scene command if you are actually in a new scene."
I must have been confused due to (1) the amount of other code I had running in my main game and (2) how I was testing both scene/show and jump when I was trying to determine what was going wrong. Thank you for setting me straight!

2. I had no idea I could do that with menus! Thank you for the new tool. I probably still will need a lot of menus due to the amount of variable triggering I have; however, this should cut it down significantly and I will see about consolidating some things. This is all really good information!

3. A Question- Why do you have the "()" after the labels? What do they do? As you can see from my examples, I have not been using them, but maybe I should be? Why would I use them?

4. I also note that you and Philat are indenting the subsequent text lines after the labels and I was not- does that change anything?

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: Persistent Image For a Character Beyond Just (Label) Scenes

#11 Post by trooper6 »

Hello!

To answer 3 and 4!

3:
So, back in the day labels couldn't take parameters, so you wouldn't put parentheses. But labels have been changed so that they can take parameters, which would go in the parentheses. So you can pass information into parameters.This could be useful if you wanted to have one morning label where different things happens depending on the day and you pass in the day, for example.
Here is documentation on that: https://www.renpy.org/doc/html/label.ht ... -statement

I think I remember reading somewhere when the label parameters became a thing, that Ren'Py runs a bit faster if you put the () on the label so I always do...that it is just better practice. I can't find anywhere where it says that now. But I switched over and just keep doing it. I'll note that the documentation does say that you should put the parentheses on your screen documentations.

4:
Whenever you put a colon, you should always indent four spaces. I think, technically you don't *have* to for labels...but you absolutely have for basically everything else, so it is better just to be consistent and indent every time you have a colon. Especially because it improves readability.
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

Dimorphodon
Newbie
Posts: 12
Joined: Sat Mar 21, 2020 9:36 pm
Contact:

Re: Persistent Image For a Character Beyond Just (Label) Scenes

#12 Post by Dimorphodon »

Thank you for the stylistic tips!

Post Reply

Who is online

Users browsing this forum: Google [Bot]