Simple tracker for change of speaker (aka applying transforms to the namebox)

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Eileen-Class Veteran
Posts: 1653
Joined: Wed Dec 04, 2013 12:33 pm

Simple tracker for change of speaker (aka applying transforms to the namebox)

#1 Post by philat » Tue Oct 29, 2019 12:31 am

This gets asked enough that I figured I'd post a relatively simple method to do this. Works as of 7.3.5.

- Character callbacks:

- _last_say_who is an internal variable Ren'py maintains. This basically just creates two extra variables to track when the speaker changes. I added underscores to _speaker_changed and _last_last_say_who for fun. (Well, really because you probably shouldn't be changing them manually.)

- There are definitely other ways to do this; I'm posting something super simple and barebones that will prob work for most cases.

Code: Select all

init 2 python:
    def speaker_change_callback(event, interact=True, **kwargs):
        global _speaker_changed, _last_last_say_who
        if event=="begin":
            _speaker_changed = (_last_say_who != _last_last_say_who)
            _last_last_say_who = _last_say_who

default _speaker_changed = False
default _last_last_say_who = ""

define e = Character("Eileen")
define a = Character("Anne")

label start:
    e "1"
    e "2"
    a "3"
    a "4"
    a "5"
    e "6"

transform bounce: # random example transform, obvs change if you wish
        ease 0.2 yoffset -10
        ease 0.2 yoffset 0
        alpha 0.0
        linear 0.4 alpha 1.0

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

        id "window"

        if who is not None:

                ## two lines added to default say screen otherwise no changes
                if _speaker_changed:
                    at bounce
                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

User avatar
Eileen-Class Veteran
Posts: 1853
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question
Projects: Slumberland
Location: Brazil

Re: Simple tracker for change of speaker (aka applying transforms to the namebox)

#2 Post by Donmai » Tue Oct 29, 2019 10:52 am

Great! Simple and effective. :)
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

Post Reply

Who is online

Users browsing this forum: No registered users