Here. I made it simpler for you.
Code: Select all
# the global variable that you can control to activate/deactivate colored mode.
default colored = False
init python:
class Char():
def __init__(self, name, color=None, colored=False):
self.name = name
self.color = color
self.colored = colored
def __str__(self):
if ((self.colored and colored) or colored) and self.color:
return "{color=%s}%s{/color}" % (self.color, self.name)
return self.name
# default your Char, giving the default name as well as the color to show when colored mode is enabled.
default fo = Char("Foxy", "#F38219")
# set the name to "variable.name" then add dynamic=True
define character.fo = Character("fo.name", dynamic=True, who_color="#F00")
# another example
default ka = Char("Kate", "#F38219")
define character.ka = Character("ka.name", dynamic=True, who_color="#F00")
# a helper label that you can re-use
label rename_char(char):
# remove white leading/trailing white spaces and if empty use the default name set earlier.
$ char.name = renpy.input("Type the name for '[char]':").strip() or char.name
return
label set_colored():
menu:
"Colored":
$ colored = True
"Non Colored":
$ colored = False
return
label start:
# call the helper label and pass the 'defaulted' character earlier, in this case, fo
call rename_char(fo)
"Make the character names colored?"
$ colored = True
"A colored character name looks like this: [fo]"
$ colored = False
"A non colored character name looks like this: [fo]"
call set_colored
fo "Great! Welcome to me ([fo])!"
You can try and play with it and see if you can make adjustments according to your need.
Basically, I retained your initial idea of having a global variable which sets the colored mode on/off.
Now all you need to do is change `colored` value to `True` or `False` in order to on/off it.
Also, no need to create another variable like `foc` earlier and use it in dialogues, you can directly use the name `fo`.
This is a working example. You can copy and paste this whole code, but of course you need to replace your start label with the contents of this code's start label.