Can I assign a color to a name/word?

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
User avatar
IchihashiMaiden
Newbie
Posts: 15
Joined: Fri Dec 08, 2017 2:00 am
Projects: Be A Good Boy (Otome) ; Iliad (VN)
itch: IchihashiMaiden
Contact:

Can I assign a color to a name/word?

#1 Post by IchihashiMaiden »

Every character in my vn is associated with a color. Hera is bronze, Agamemnon is red, Achilles is dark blue, etc.
What I would like to do is, everytime I insert the name of a character in dialogue, it appears in that color, so it stands out.

Is there a way to do this automatically, or do I have to insert the color code manually each time someone is mentioned?
I have no idea what I'm doing.
(Character in icon belongs to nomnomnami on itch.io)

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Can I assign a color to a name/word?

#2 Post by Nero »

You could define the character and give it the color code like so:

Code: Select all

    $ a = Character(_("Agamemnon:"),
                        color="ff0000")

    a "Cool my name is in red!"

User avatar
IchihashiMaiden
Newbie
Posts: 15
Joined: Fri Dec 08, 2017 2:00 am
Projects: Be A Good Boy (Otome) ; Iliad (VN)
itch: IchihashiMaiden
Contact:

Re: Can I assign a color to a name/word?

#3 Post by IchihashiMaiden »

Code: Select all

define C1 = Character("Chryses", color="3d352f")
define GS = Character("Greek Soldiers", color="915122")
define A1 = Character("Agamemnon", color="9F111B")
define A2 = Character("Achilles", color="045991")
define dA1 = Character("Apollo", color="ffe766")
define dZ1 = Character("Zeus", color="e6c200")
define dH1 = Character("Hera", color="948532")
This works for coloring the name while THAT person is talking, but it doesn't color the name if someone ELSE is talking ABOUT that person. :<
I have no idea what I'm doing.
(Character in icon belongs to nomnomnami on itch.io)

Nero
Veteran
Posts: 248
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Can I assign a color to a name/word?

#4 Post by Nero »

Ah my bad don't know about that never used such feature in my games but I would like to know also if someone can help.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Can I assign a color to a name/word?

#5 Post by Ocelot »

Here is a solution using Custom Text Tags:

Code: Select all

init python:
    def char_tag(tag, argument, contents):
        char = getattr(renpy.store, contents[0][1])
        contents = [ 
                       (renpy.TEXT_TAG, "color=" + char.who_args["color"]), 
                       (renpy.TEXT_TEXT, char.name), 
                       (renpy.TEXT_TAG, "/color") 
                   ]
        return contents

    config.custom_text_tags["char"] = char_tag

define e = Character("Eileen", who_color="ff0000")

label start:
    scene bg room
    show eileen happy
    e "You've created a new Ren'Py game."
    
    # Notice that I use character object name, not character name here
    e "Starring me, {char}e{/char}"
    e "Once you add a story, pictures, and music, you can release it to the world!"
    return
It extracts name and color from character object itself. To test, create a new project, replace content of script.rpy with this code and run the game.

(We really need a way to define self-closing tags, I would prefer to use {char=e} here)
< < insert Rick Cook quote here > >

User avatar
IchihashiMaiden
Newbie
Posts: 15
Joined: Fri Dec 08, 2017 2:00 am
Projects: Be A Good Boy (Otome) ; Iliad (VN)
itch: IchihashiMaiden
Contact:

Re: Can I assign a color to a name/word?

#6 Post by IchihashiMaiden »

Oh.. I was hoping I could avoid using "init" entirely in this VN. Quite frankly, I find the "init" to be incredibly intimidating for some reason. I don't understand it at all, and the more reading I try to do on it, the more confused I feel. It's a bit overwhelming. (Maybe this is because I never took a proper class on coding, and have been learning by trial and error.)

I guess, then, my only option is to either drop the idea, or do it manually.
Thank you though. I appreciate the effort and suggestion.
I have no idea what I'm doing.
(Character in icon belongs to nomnomnami on itch.io)

Post Reply

Who is online

Users browsing this forum: No registered users