Custom Text Tags#
Ren’Py Custom Text Tags (CTT) is the opportunity to create new text tags which can be quite useful in your game.
For example, famous Kinetic Text Tags create many unusual visual effects (some of which were eventually implemented in the Ren’Py engine itself).
Toggleable Walkthrough#
Let’s suppose that you want to give a hint to player, what consequences they’ll get choosing this or that option:
And if they want to play without the hints, they can toggle Walkthrough OFF:
Now imagine that, in order to implement this, at every choice you will have to check the condition: whether walkthrough is enabled or disabled, and make 2 variants of every choice menu.
That could be a lot of work, but with custom text tags we can make that much easier:
menu:
"What am I gonna do with the rest of the day?"
"Ask Tisha out{wg}You will spend more time together":
jump day6ev_tisha
"Go to Kowloon Bay Park{wy}You will meet new people":
jump day6ev_park
"Play Civilization{wg}You will get +INT{wr}Tisha will hate you":
"I spent the evening playing Civilization."
"""I went to bed really late (or early...
Because that was in the morning)."""
"Leave the city{wr}The End":
"I spent the rest of my days in blissful meditation."
return
All you have to do is define three colors (or as many as you want) for the hints, and use tags, e.g.: {wr} for red, {wy} for yellow, {wg} for green hints. And those hints will be shown only when walkthrough mode is ON.
Here’s the code for this (I put it in file ctt.rpy):
define walkthrough_text_size = 24
default wt = True
init python:
def wr_tag(tag, argument, contents):
""" Red Walkthrough hints """
if not wt:
return ""
return [
(renpy.TEXT_PARAGRAPH, ""),
(renpy.TEXT_TAG, f"size={walkthrough_text_size}"),
(renpy.TEXT_TAG, "color=#F00"),
] + contents + [
(renpy.TEXT_TAG, "/color"),
(renpy.TEXT_TAG, "/size")
]
def wy_tag(tag, argument, contents):
""" Yellow Walkthrough hints """
if not wt:
return ""
return [
(renpy.TEXT_PARAGRAPH, ""),
(renpy.TEXT_TAG, f"size={walkthrough_text_size}"),
(renpy.TEXT_TAG, "color=#EE0"),
] + contents + [
(renpy.TEXT_TAG, "/color"),
(renpy.TEXT_TAG, "/size")
]
def wg_tag(tag, argument, contents):
""" Green Walkthrough hints """
if not wt:
return ""
return [
(renpy.TEXT_PARAGRAPH, ""),
(renpy.TEXT_TAG, f"size={walkthrough_text_size}"),
(renpy.TEXT_TAG, "color=#0F0"),
] + contents + [
(renpy.TEXT_TAG, "/color"),
(renpy.TEXT_TAG, "/size")
]
config.custom_text_tags["wr"] = wr_tag
config.custom_text_tags["wy"] = wy_tag
config.custom_text_tags["wg"] = wg_tag
And to switch walkthrough ON or OFF, you just set wt to
True or False. Depending on that, the tag function will
return either empty string or the content of the hint.
(All the explanations for the code can be found in the official Ren’Py documentation.)
You can, of course, make wt a persistent variable and toggle
walkthrough mode in the Preferences screen. That will be described in
another tutorial.