Callback - Character Indicators [SOLVED]

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
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Callback - Character Indicators [SOLVED]

#1 Post by TellerFarsight »

Hey all!
I have a question about character callbacks that's really stumping me. I've seen them used pretty cleanly for beepy voices and lip flaps and all that, but I'm trying to use them for custom character indicators, kind of like CTC indicators. To do this, I need the character to be an argument in the callback function, but for some reason, it's not working.
The idea is that a talk indicator will appear above each character's head whenever they're talking, not in the textbox. Each character has a "current position" attribute, so I should be able to put the indicator at their current position. It appears when they begin talking and disappears when the interaction is over (I think I've done that part right?)
Untitled.png
Untitled.png (9.79 KiB) Viewed 2395 times
The issue is getting the function to accept the character as an argument. If I put it at the end, like here, it returns the error "non-default argument follows default argument," which I don't fully understand.

Code: Select all

init -1 python:
    def talking_stick(event, interact=True, char):
        if not interact:
            return
        if event == "begin":
            renpy.show("talk_indic", at_list=[current_pos(char.xpos,char.ypos - 48*3,0.5)])
        elif event == "end":
            renpy.hide("talk_indic")
            
...
...
...

define a = Character("Aggy", image="aggy", callback=talking_stick(Aggy))
I tried rearranging the order of the arguments in the function like so:

Code: Select all

def talking_stick(char, event, interact=True):
but then it returns the error "talking_stick() takes at least 2 arguments (1 given)"

So I'm not really sure what to do. Any ideas?
Last edited by TellerFarsight on Sun Apr 15, 2018 1:48 pm, edited 1 time in total.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Callback - Character Indicators

#2 Post by kivik »

Ooh, I had this problem before and this thread has the solution!

viewtopic.php?f=8&t=48870#p482245

Something like this:

Code: Select all

        from functools import partial # import the python function
        def talking_stick(char, event_name, *args, **kwargs):
                # your code here
    define a = Character("Aggy", image="aggy", callback=partial(talking_stick,"Aggy"))

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Callback - Character Indicators

#3 Post by TellerFarsight »

Works like a charm! It's literally perfect.

Code: Select all

init -1 python:
    from functools import partial
    def talking_stick(char, event_name, interact=True, **kwargs):
        if not interact:
            return
        if event_name == "begin":
            renpy.show("talk_indic", at_list=[current_pos(char.xpos,char.ypos - 48*3,0.5)])
        elif event_name == "end":
            renpy.hide("talk_indic")
            
...
...
...

define a = Character("Aggy", image="aggy", callback=partial(talking_stick,Aggy))
but if anyone has a solution that doesn't require importing partial, toss it on in because it might be more efficient.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: Callback - Character Indicators [SOLVED]

#4 Post by philat »

The latest (March 2018) patreon article (viewtopic.php?f=51&t=47328 ) could be adapted for this. You can also use renpy.curry instead of partial, although I don't know whether that would make any difference for performance.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Callback - Character Indicators [SOLVED]

#5 Post by trooper6 »

Also just for the record, you don't need renpy.curry or partial. You can pass keyword arguments to the callback using the cb_ prefix.
So you could do:

Code: Select all

define a = Character("Aggy", image="aggy", callback=talking_stick, cb_char=Aggy)
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot]