How can I display something different if the same person talks more than once in a row?

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
Braydxne
Regular
Posts: 50
Joined: Tue Aug 08, 2017 4:03 am
Projects: DR: Chains of Trust
Contact:

How can I display something different if the same person talks more than once in a row?

#1 Post by Braydxne » Wed Sep 09, 2020 6:58 pm

For my game, I want to have it where an animation will play if it's the characters first time talking. I have that set up and everything but now I'm unsure how to make it so it stores who spoke last and won't use the animation if they speak multiple times in a row. This is what I have in screens.rpy

Code: Select all

default lastwho = "None"

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

    window:
        id "window"

        if who is not None:

            add "portrait" xalign 0.0 yalign 2.6
            if lastwho == who:
                add "staticcharimg" xalign 0.0 yalign 2.5
            else:
                add "charimg" xalign 0.0 yalign 2.5
                $ lastwho = who

            add "outlines" xalign 0.0 yalign 2.6

            window:
                id "namebox"
                style "namebox"
                text who id "who"
It seems to never set the variable and always call the static image rather than the animated one.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: How can I display something different if the same person talks more than once in a row?

#2 Post by hell_oh_world » Wed Sep 09, 2020 8:12 pm

If it helps, renpy already automatically stores the last say's who and what. it should be stored in the _last_say_who and _last_say_what variables. Also might be better to use character callbacks i guess and append to a list the characters then check if its already in the list or not to see if it is the first time the character talked. https://www.renpy.org/doc/html/config.h ... s_callback or https://www.renpy.org/doc/html/config.h ... r_callback

User avatar
Braydxne
Regular
Posts: 50
Joined: Tue Aug 08, 2017 4:03 am
Projects: DR: Chains of Trust
Contact:

Re: How can I display something different if the same person talks more than once in a row?

#3 Post by Braydxne » Wed Sep 09, 2020 10:07 pm

hell_oh_world wrote:
Wed Sep 09, 2020 8:12 pm
If it helps, renpy already automatically stores the last say's who and what. it should be stored in the _last_say_who and _last_say_what variables. Also might be better to use character callbacks i guess and append to a list the characters then check if its already in the list or not to see if it is the first time the character talked. https://www.renpy.org/doc/html/config.h ... s_callback or https://www.renpy.org/doc/html/config.h ... r_callback
I think the callback thing would work if it weren't for the fact that I need it to display the animation even if it's already displayed it for that character before, I just need it to not display the animation if the same person is talking multiple times in a row. The _last_say_who would be the perfect solution! However it returns the shortened name for the character instead of the one I use for nameboxes. Is there a way to change this? It would be exactly what I need.

Example:

Code: Select all

define maria = Character("Maria Delgado",
color = "fcfcfc",
image="maria",)
_last_say_who returns "maria" rather than "Maria Delgado", but the say screen's who is "Maria Delgado", so the two will never be the same.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: How can I display something different if the same person talks more than once in a row?

#4 Post by hell_oh_world » Wed Sep 09, 2020 10:18 pm

try to do this instead. not really familiar with the two variables that I said so I thought that it would return the exact name. you can use the getattr function if it returns the variable name instead.

Code: Select all

init python:
  def getLastSayWhoName(): # returns an empty string if the character is not found or the name if it is.
    char = store.character if hasattr(store, "character") else None
    lsw = store._last_say_who or ""
    search = store if char is None else char
    
    return getattr(search, lsw).name if hasattr(search, lsw) else ""
    
label start:
  $ w = getLastSayWhoName()
  "[w]"

User avatar
Braydxne
Regular
Posts: 50
Joined: Tue Aug 08, 2017 4:03 am
Projects: DR: Chains of Trust
Contact:

Re: How can I display something different if the same person talks more than once in a row?

#5 Post by Braydxne » Wed Sep 09, 2020 10:49 pm

hell_oh_world wrote:
Wed Sep 09, 2020 10:18 pm
try to do this instead. not really familiar with the two variables that I said so I thought that it would return the exact name. you can use the getattr function if it returns the variable name instead.

Code: Select all

init python:
  def getLastSayWhoName(): # returns an empty string if the character is not found or the name if it is.
    char = store.character if hasattr(store, "character") else None
    lsw = store._last_say_who or ""
    search = store if char is None else char
    
    return getattr(search, lsw).name if hasattr(search, lsw) else ""
    
label start:
  $ w = getLastSayWhoName()
  "[w]"
Thank you so much! That definitely works! My only issue now is I don't think it works properly when I use it in a screen, but I'm not sure where else to put it so it runs whenever a character speaks. I need the portrait image to be under the namebox, is it possible to do this? Or is there just an issue with how I set it up, because the image never animates even when the two values aren't the same.

Code: Select all

default lastwho = "None"

screen say(who, what):
    style_prefix "say"
    $print who
    $print lastwho
    window:
        id "window"

        if who is not None:

            if not who == "System":
                add "portrait" xalign 0.0 yalign 2.6

                if who == lastwho:
                    $print "Static"
                    add "staticcharimg" xalign 0.0 yalign 2.5
                else:
                    $print "Dynamic"
                    add "charimg" xalign 0.0 yalign 2.5
                    $ lastwho = getLastSayWhoName()
                    $print "Updated"
                    $print lastwho

                add "outlines" xalign 0.0 yalign 2.6

            window:
                id "namebox"
                if not who == "System":
                    style "namebox"
                else:
                    style "sysbox"
                text who.upper() id "who"



        text what id "what"

User avatar
Braydxne
Regular
Posts: 50
Joined: Tue Aug 08, 2017 4:03 am
Projects: DR: Chains of Trust
Contact:

Re: How can I display something different if the same person talks more than once in a row?

#6 Post by Braydxne » Thu Sep 10, 2020 12:15 am

I found a solution! If anyone else needs it you can use

Code: Select all

if (len(_history_list) == 0) or (len(_history_list) > 0 and _history_list[-1].who != who):
! I got it from https://lunachai.com/blog/loony-renpy-c ... ransitions! Thank you for your help hell_oh_world! ^^

Post Reply

Who is online

Users browsing this forum: No registered users