The February community event is coming up this Saturday @ 1800PST. We create a function to change what type of character is speaking instead of changing it in-line.


Commmunity Event

The community event day is coming up quickly!

DMR beta

The DMR beta is scheduled to begin at the end of the week, and we’ll be trying out an extended/rolling format, where the beta will be open for several weeks, and new routes will be added to the build as soon as they are available. If you want to join in, be sure to subscribe to the Throne tier on our Patreon!

Ren’Py character overwriting

When we define speaking characters, we can add a variety of attributes, such as the color of their name, whether they have a side portrait, and whether their name shows up on screen, among other things.

To use these characters, we usually explicitly decide which one of them is speaking in-line.

lee at left, dialogue box centered, jed at right. jed spoke two sentences, one with a prepended BARKEEP name identifier. first sentence is yeah, he gets all wound up sometimes and aint nothing changes his mind. second sentence is for what its worth, stranger, like i told you afore, i dont think you done it.
ujpbc_name m_4 t_4 "Yeah, he gets all wound up sometimes and ain't nothing changes his mind."
ujpbc m_n t_n "For what it's worth, stranger, like I told you afore, I don't think you done it."

The first time Jed speaks, his name “BARKEEP” shows up, and the character speaking it is ujpbc_name. The second time he speaks, we don’t want the name to show up, so we use a different character ujpbc. Adding this in-line can get very tedious quickly, especially since at the time of writing, you aren’t usually sure about how the dialogue should look in-game. Conveniently, how dialogue should look is usually easily split into sections: it is not very common to switch often between various visual layouts since it can be distracting.

So instead of defining the character that is speaking each and every line, why don’t we define them at the start of the section?

# define the various characters and their styles
# use default for the character that will be redefined throughout the game
# use define for all static characters

default h = Character("Hollis Dalton", what_prefix='"', what_suffix='"', color="#eedec7", ctc="ctc_pic", image="hollis") # we always write his dialogue as `h "this is my dialogue"`
define hp = Character("Hollis Dalton", what_prefix = '"', what_suffix = '"', color="#eedec7", ctc="ctc_pic", image="hollis_p", window_left_padding=25, window_right_padding=25, what_xmaximum=750,)  
define hpbc = Character(None, what_prefix = '"', what_suffix = '"', who_color="#472F47", ctc=None, image="hollis_pbc", window_left_padding=0, window_right_padding=0, what_color="#6D396D", kind=nvl,what_text_align=1.0,what_xmaximum=400,  who_xoffset=510, who_xmaximum=800)
define hpbc_name = Character("Hollis Dalton", what_prefix = '"', what_suffix = '"', who_color="#472F47", ctc=None, image="hollis_pbc", window_left_padding=0, window_right_padding=0, what_color="#6D396D", kind=nvl,what_text_align=1.0,what_xmaximum=400,  who_xoffset=510, who_xmaximum=800)
define h_adv = Character("Hollis Dalton", what_prefix='"', what_suffix='"', color="#eedec7", ctc="ctc_pic", image="hollis")
define h_tp = Character("Hollis Dalton", what_prefix='"', what_suffix='"', color="#eedec7", ctc="ctc_pic", image="hollis")

# define a function that will change which character `h` is referring to
def wm(w=None):
    if w == "s":
        store.h = store.h_side
    elif w == "cgnvl":
        store.h = store.hcg_nvl
    elif w == "pbc":
        store.h = store.hpbc
    elif w == "side":
        store.h = store.hp
    else: # adv
        store.h = store.h_adv

# use in-game

$ wm("s")
h "Hello I am a side_nvl version"
$ wm("cgnvl")
h "And CG NVL kind"
$ wm()
h "Regular old side portrait"
showing the # use in-game block of hollis speaking with various versions

This of course doesn’t catch every case (we still have to go in and specify when to us jpbc_name for instance), but it makes it a lot faster than doing a find/replace to change every in-line character once we have determined which character should be speaking in a particular section. It allows a writer to focus on writing, without having to spend some time deciding which character to use (or even knowing anything about the programming/design/implementation side of things).

Questions or Comments?

Feel free to send in any AG-related questions! Our Ask Box is always open.

Thanks so much for all of your amazing support, and stay safe out there!