[Solved] Avoiding using a {color} tag each time a word is mentioned?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

[Solved] Avoiding using a {color} tag each time a word is mentioned?

#1 Post by Adrian_DVL »

Hello!

So, I want to highlight the name of the characters with her own color each time they are mentioned in a dialogue, each time another character mentions them. In general, each time their name appears on a text box.

So far, I've been doing it by adding, again and again, a {color} tag each time a name appears, but it happens that the characters of my game are very affectionate and they like to call each other by their names.

So is there a way to display a certain word in a certain color each time it appears on a text box without having to use a {color} tag?
Last edited by Adrian_DVL on Thu Apr 18, 2019 8:49 am, edited 1 time in total.

User avatar
Marionette
Regular
Posts: 128
Joined: Thu Apr 21, 2011 12:04 pm
Completed: https://marionette.itch.io/
Projects: Get Meowt of Here
Deviantart: rexx9224
itch: marionette
Location: Ireland
Discord: Marionette#2995
Contact:

Re: Avoiding using a {color} tag each time a word is mentioned?

#2 Post by Marionette »

You could try setting the name up with the tag as a variable and adding it that way.
Eg

Code: Select all

#Define it like so
$Mark = "{color=#ffffff}Mark{/color}"

# Use it like so
"Hey its [Mark]."

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Avoiding using a {color} tag each time a word is mentioned?

#3 Post by Remix »

If you define your characters in the character namespace ( define character.e = Character(...) rather than just define e = Character(...) ) you can add a bit of automation using iteration and say_menu_text_filter:

Code: Select all

default pc = "Bob"
define character.b = Character("[pc]", who_color="00F")

define character.e = Character("Eileen", who_color="F00")


init python:

    char_colours = {}

    for key in character.__dict__:
        char = getattr( character, key )
        if hasattr( char, 'who_args' ):
            colour = char.who_args.get('color', None)
            if colour:
                char_colours[ char.name ] = (
                    "{{color={colour}}}{name}{{/color}}".format(
                        name=char.name, colour='#{0}'.format(colour)))

    def colourize_names( str_to_test ):
        for name in char_colours:
            str_to_test = str_to_test.replace(name, char_colours[name]) 
        return str_to_test

define config.say_menu_text_filter = colourize_names

label start:
    e "My name is Eileen..."
    b "Hi Eileen, my name's [pc]"
Frameworks & Scriptlets:

Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Re: Avoiding using a {color} tag each time a word is mentioned?

#4 Post by Adrian_DVL »

Tried both ways and both work! I like best Remix's one, since I don't even have to use square brackets, but to mark this thread as solved.

Anyway, thank you so much to both of you!

Post Reply

Who is online

Users browsing this forum: No registered users