[SOLVED] Namebox transform at leave and enter?

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
Wildmask
Newbie
Posts: 20
Joined: Sun Oct 02, 2016 1:18 pm
Contact:

[SOLVED] Namebox transform at leave and enter?

#1 Post by Wildmask »

I'm attempting to have the namebox change depending on if it is "leaving" the scene or "entering" it.
What I am trying to accomplish is like this video. (2:38 - 2:40).
You can see how when the other character starts speaking, the first character's (Speaker A's) name moves right and disappears, while the entering name (Speaker B) moves in left and appears.
I've managed to replicate the "entering and appearing" part like so:

Code: Select all

screen say(who, what):
    style_prefix "say"

    if not config.skipping and what: ##This keeps the sound from playing when the dialogue is being skipped.
        on 'hide' action Play('sound', 'audio/sfx/next.wav') ## This plays the sound whenever the window is hidden.

    window:
        id "window"

        if who is not None:

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


        text what id "what"

Code: Select all

style say_label:
    properties gui.text_properties("name", accent=True)

transform say_label:
    xalign 0.2 yalign 0.5 alpha 0.0
    linear 0.1 xalign gui.name_xalign alpha 1.0
But the issue with this is it activates every time you advance dialogue. I want the name to stay still on the screen even if you advance dialogue several times as long as the same Speaker is still talking. As soon as it switches out or switches in to a new person, I want the respective animations to play out. Furthermore with this method, it only plays the animation for entering, not leaving.
Forgive me if this is a simple trick I'm failing to pull off. I haven't touched Ren'Py in over half a decade, and even back then I was a newbie, so stuff like this is still a little new to me.
Thank you and have a good day. :)
Last edited by Wildmask on Sat Jun 01, 2024 12:43 am, edited 1 time in total.
If you try, you risk failure. If you don't try at all, you guarantee it.
Have a good day, week, year! :)

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1060
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Namebox transform at leave and enter?

#2 Post by m_from_space »

Wildmask wrote: Sat May 25, 2024 9:15 pm Forgive me if this is a simple trick I'm failing to pull off. I haven't touched Ren'Py in over half a decade, and even back then I was a newbie, so stuff like this is still a little new to me.
This is actually not a simple trick. The problem here in general is that the "say" screen hides and shows itself with every new dialogue line. That's the reason the sound plays and using an "on hide" event is not working. It's just that you cannot actually see that it is hiding itself, because it doesn't get rendered.

So I suggest saving the last character's name in a variable and then just check if the current dialogue's speaker is different from the last one and depending on that you show a different animation for the namebox. I hope this gives you the general idea:

Code: Select all

define e = Character("Eileen")
define l = Character("Leila")

transform who_leaving:
    alpha 1.0 xoffset 0
    linear 0.5 alpha 0.0 xoffset -50

transform who_entering:
    alpha 0.0 xoffset -50
    linear 0.5 alpha 1.0 xoffset 0

default last_who = None

screen say(who, what):
    style_prefix "say"

    default leaving = True

    on "hide" action SetVariable("last_who", who)

    window:
        id "window"

        if who is not None or last_who is not None:

            window:
                id "namebox"
                style "namebox"
                # make sure to give your namebox a fixed height, otherwise Renpy freaks out
                ysize 50
                # the current speaker is the narrator, but the last one was a name
                if who is None:
                    text last_who id "who" at who_leaving
                # the current speaker is the first one after a narrator or the beginning of the game
                elif last_who is None:
                    text who id "who" at who_entering
                # the speaker changes
                elif last_who != who:
                    if leaving:
                        text last_who id "who" at who_leaving
                        timer 0.5 action SetScreenVariable("leaving", False)
                    else:
                        text who id "who" at who_entering
                # the speaker stays the same, don't animate anything
                else:
                    text who id "who"

        text what id "what"

# The game starts here.
label start:

    e "Hello, I am Eileen!"

    l "And I am Leila."
    l "Speaking a second time."

    "I am the narrator."

    return
P.S. You might want to reset "last_who" to None everytime you have some cut scene in between. Or maybe there is another solution, I don't know.

User avatar
Wildmask
Newbie
Posts: 20
Joined: Sun Oct 02, 2016 1:18 pm
Contact:

Re: Namebox transform at leave and enter?

#3 Post by Wildmask »

Holy cow you are incredible!! This is perfect!!

Truthfully, I had tried making my own "if who is None:" clause in the "screen say", utilizing "_last_say_who" to grab the name, but was having issue with transforming the given value ("e", if the name is "Eileen") into the real name. Your solution is much more practical and smart! And it definitely give me a good idea of how to handle any future issues that mirror this one. Thank you!
If you try, you risk failure. If you don't try at all, you guarantee it.
Have a good day, week, year! :)

Post Reply

Who is online

Users browsing this forum: No registered users