Ren'Py Ren'Py Custom Text Tag With Arguments

Evergene

Newbie
Oct 30, 2021
45
61
Was struggling to figure out a way to pass something as text arguments until I figured out a kind of decent way to handle the text arguments and this is the way I figured it out, hope it can be helpful for someone struggling with the same thing!

You don't have permission to view the spoiler content. Log in or register now.
You don't have permission to view the spoiler content. Log in or register now.

And then in the dialogue you simply use this:
person "{whisper=This will be formatted as a whisper message.}"

There's probably way better ways to approach this, but this is what I could think of.
 
  • Like
Reactions: galadh

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,111
14,798
There's probably way better ways to approach this, but this is what I could think of.
There's many others way to do this, the easiest, to build and to use, being:

define person_w( "name", what_color="#969696", what_prefix="{image=whisper.jpg}{alt}
whisper{/alt}{i}", what_suffix="{/i}" )
.

There's less works to do to use it, since it just need a trailing "_t" at the end of the sayer name ; what also mean less risk of typo. And in top of that, like the color is defined at sayer level, and not tag level, people who defined different colors, depending of the sayer, can continue to use those different colors.


Incidentally, the use of a self closed tag isn't the best approach, since is force you to provide the dialog as argument for the tag. A generic tag would have been better:
Python:
init python:

    def whisper_tag(tag, argument, contents):
        return [ store.whisperOpen + contents + store.whisperClose ]

    config.custom_text_tags["whisper"] = whisper_tag

define whisperOpen = [ ( renpy.TEXT_TAG, "color=#969696" ), ( renpy.TEXT_TAG, "i" ), ( renpy.TEXT_TAG, "image=whisper.png" ), 
                       ( renpy.TEXT_TAG, "alt" ),  ( renpy.TEXT_TEXT, "whisper" ),( renpy.TEXT_TAG, "/alt" ) ] ]
define whisperClose = [ ( renpy.TEXT_TAG, "/i" ), ( renpy.TEXT_TAG, "/color" ) ]

label whatever:
    person "{whisper}This will be formatted as a {color=#0F0}whisper message{/color} but... {size=-10}Shhh it's a secret{/size}.{/whisper}"
 

Evergene

Newbie
Oct 30, 2021
45
61
There's many others way to do this, the easiest, to build and to use, being:

define person_w( "name", what_color="#969696", what_prefix="{image=whisper.jpg}{alt}
whisper{/alt}{i}", what_suffix="{/i}" )
.

There's less works to do to use it, since it just need a trailing "_t" at the end of the sayer name ; what also mean less risk of typo. And in top of that, like the color is defined at sayer level, and not tag level, people who defined different colors, depending of the sayer, can continue to use those different colors.


Incidentally, the use of a self closed tag isn't the best approach, since is force you to provide the dialog as argument for the tag. A generic tag would have been better:
Python:
init python:

    def whisper_tag(tag, argument, contents):
        return [ store.whisperOpen + contents + store.whisperClose ]

    config.custom_text_tags["whisper"] = whisper_tag

define whisperOpen = [ ( renpy.TEXT_TAG, "color=#969696" ), ( renpy.TEXT_TAG, "i" ), ( renpy.TEXT_TAG, "image=whisper.png" ),
                       ( renpy.TEXT_TAG, "alt" ),  ( renpy.TEXT_TEXT, "whisper" ),( renpy.TEXT_TAG, "/alt" ) ] ]
define whisperClose = [ ( renpy.TEXT_TAG, "/i" ), ( renpy.TEXT_TAG, "/color" ) ]

label whatever:
    person "{whisper}This will be formatted as a {color=#0F0}whisper message{/color} but... {size=-10}Shhh it's a secret{/size}.{/whisper}"
Oh that's a really well made approach to this, I'm still pretty new to python and ren'py so it's difficult so far to find the most efficient approaches, but I do understand now how you handle the dynamic usage with _t, thank you for your input and guidance!