[SOLVED] Accessing the content of say statement inside character callback?

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
wendigotypes
Newbie
Posts: 2
Joined: Fri Apr 12, 2024 1:52 pm
itch: wendigotypes
Contact:

[SOLVED] Accessing the content of say statement inside character callback?

#1 Post by wendigotypes »

Hello!

I wrote a character callback function following the example listed under https://www.renpy.org/doc/html/character_callbacks.html:

Code: Select all

init python:
    import functools
    def callbop(event, char, interact=True,**kwargs):
        if not interact:
            return
        if event == "begin" and renpy.showing(char):
            renpy.show(char, at_list=[bop])
The char gets passed in like so:

Code: Select all

define c = Character("Cicada Christie", image="cicada", callback=functools.partial(callbop, char="cicada"))

This function just makes it so that the speaking character bops up and down a little bit.

Now, I would really like to check if the content of the say statement that triggered the callback was something like "..." because I only want them to bop when they actually say words. Ideally, I would like to pass the content of the say statement to the callback as an argument. Is there maybe some clever way to do that? Or if that's not possible, maybe there's another way to access the content of the last say statement? Or maybe, if all else fails, is there a way to change the character callback function on the fly?

Thanks to anyone who takes the time to read this :)
Last edited by wendigotypes on Sat Apr 13, 2024 3:22 am, edited 1 time in total.

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

Re: Accessing the content of say statement inside character callback?

#2 Post by philat »

Merely linking because I remember seeing this discussion but did not actually try any of it: viewtopic.php?p=558474

User avatar
wendigotypes
Newbie
Posts: 2
Joined: Fri Apr 12, 2024 1:52 pm
itch: wendigotypes
Contact:

Re: Accessing the content of say statement inside character callback?

#3 Post by wendigotypes »

Thank you for that link! I actually just got it to work using the function renpy.last_say() :)

In case somebody comes along in the future and wonders how exactly:

Code: Select all

    def callbop(event, char, interact=True,**kwargs):
        if not interact:
            return
        what = renpy.last_say().what
        if event == "begin" and renpy.showing(char) and not set(what).issubset(set('. ')):
            if what.startswith('('): 
                renpy.show(char, at_list=[smallbop])
            elif what.upper() == what or what.endswith('!!'):
                renpy.show(char, at_list=[bigbop])               
            else: 
                renpy.show(char, at_list=[bop])
                

Post Reply

Who is online

Users browsing this forum: BBN_VN, Majestic-12 [Bot], snotwurm