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
Message
Author
philat
Eileen-Class Veteran
Posts: 1660
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

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: https://renpy.org/doc/html/character_callbacks.html

- _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
    config.all_character_callbacks.append(speaker_change_callback)

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"
    return

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

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

    window:
        id "window"

        if who is not None:

            window:
                ## 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
Donmai
Eileen-Class Veteran
Posts: 1854
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
Contact:

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. :)
Image
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