**kwargs must be in the code.
What it means is that you can add in additional keyword arguments to your callback, if you like. But if you don't need additional information passed to your callback, you can ignore it--but don't delete it.
How would you use a keyword arg? Well there are many ways depending on your imagination. But here is one example.
Let's say you want clicks to play when your characters are speaking using slow text...but not when they are not speaking. You could make a callback like so:
Code: Select all
init -1 python:
renpy.music.register_channel("Chan1", mixer= "sfx", loop=True)
def clicks(event, **kwargs):
if event == "show" or event == "begin":
renpy.music.play("click.wav", channel="Chan1")
if event == "slow_done" or event == "end":
renpy.music.stop(channel="Chan1")
And then you give your callback to a character and you are good to go:
Code: Select all
define e = Character('Eileen', color="#c8ffc8", what_slow_cps=20, what_slow_abortable=False, callback=clicks)
What if you have two characters and you want a different click sound to happen for each one? You could make two different callbacks:
Code: Select all
init -1 python:
renpy.music.register_channel("Chan1", mixer= "sfx", loop=True)
def clicks1(event, **kwargs):
if event == "show" or event == "begin":
renpy.music.play("high_click.wav", channel="Chan1")
if event == "slow_done" or event == "end":
renpy.music.stop(channel="Chan1")
def clicks2(event, **kwargs):
if event == "show" or event == "begin":
renpy.music.play("low_click.wav", channel="Chan1")
if event == "slow_done" or event == "end":
renpy.music.stop(channel="Chan1")
And then define your two characters:
Code: Select all
define e = Character('Eileen', color="#c8ffc8", what_slow_cps=20, what_slow_abortable=False, callback=clicks1)
define f = Character('Faye', color="#c8ffc8", what_slow_cps=20, what_slow_abortable=False, callback=clicks2)
That would work...but you are repeating code, and whenever you start repeating code there is probably a more efficient way to do what you want to do. What happens if instead of just two different clicks...you had 10? Then you'd have to make ten different callbacks? Nope, you can just have one callback and use a keyword arg. That would look like this (we are going to add a keyword argument called "char" that tells us which character is speaking and then we will decide which click sound to play based on that):
Code: Select all
init -1 python:
renpy.music.register_channel("Chan1", mixer= "sfx", loop=True)
def clicks(event, char=1, **kwargs):
if event == "show" or event == "begin":
if char == 1:
renpy.music.play("high_click.wav", channel="Chan1")
if char == 2:
renpy.music.play("low_click.wav", channel="Chan1")
if char == 3:
renpy.music.play("med_click.wav", channel="Chan1")
if event == "slow_done" or event == "end":
renpy.music.stop(channel="Chan1")
Then you make your characters, and include a callback keyword...which in this case looks like 'cb_char':
Code: Select all
define e = Character('Eileen', color="#c8ffc8", what_slow_cps=20, what_slow_abortable=False, callback=clicks, cb_char=1)
define f = Character('Faye', color="#c8ffc8", what_slow_cps=20, what_slow_abortable=False, callback=clicks, cb_char=2)
define r = Character('Roger', color="#c8ffc8", what_slow_cps=20, what_slow_abortable=False, callback=clicks, cb_char=3)