Ren'Py includes the ability to execute callbacks when various events occur during dialogue. This is done by giving the callback argument to Character(), or setting the config.character_callback or config.all_character_callbacks variables.
The character callback is called with a single positional argument, the event that occured. Possible events are:
The callback is called with at least one keyword argument:
Other values of the positional argument and additional keyword arguments may be supplied in the future. The callback should coded to ignore arguments it does not understand.
This example plays beeps in place of a character voice, when slow text is enabled:
init python:
def beepy_voice(event, interact=True, **kwargs):
if not interact:
return
if event == "show_done":
renpy.sound.play("beeps.ogg")
elif event == "slow_done":
renpy.sound.stop()
define pike = Character("Christopher Pike", callback=beepy_voice)
label start:
pike "So, hanging out on Talos IV, minding my own business, when..."