init python:
class ConditionValue( renpy.python.RevertableObject ):
def __init__( self, variable, default, *args ):
'''
ConditionSwitch-like object.
- variable [String]
Name of the variable (should be scalar-like and not an object attribute)
that will be used to test the condition.
- default [whatever]
Value to return by default. Either because the variable do not exist yet,
or because its value match none of the defined conditions.
- As many tuples ( "condition value", "returned value" ) as you want.
The "condition value" is the expected value for the variable, while the
"returned value" will be what the object return if the condition match.
'''
self.variable = variable
self.default = default
self.conditions = args
def __call__( self ):
# If the variable do NOT exist, return the value defined
# as default.
if not hasattr( store, self.variable ):
return self.default
# Get the current value
value = getattr( store, self.variable )
# Test all the defined values
for v, rv in self.conditions:
# If the "condition value" correspond, return the associed
# "value to use".
if value == v:
return rv
# The value correspond to none of the "condition value",
# therefore, return the default value.
return self.default
define mcSpouseGender = "Female"
# The color for the name (/who_color/) will be based on the
# /mcSpouseGender/ variable. By default the color is white (/#FFF/).
# But if the variable value is "Female", the color will be pinkish (/#FF80FF/)
# and if the variable value is "Male", it will be blue (/#00F/).
define mcSpouse = Character( "[mcSpouseName]", who_color=ConditionValue( "mcSpouseGender", "#FFF", ( "Female", "#FF80FF" ), ( "Male", "#00F" ) ) )
default mcSpouseName = "Alice"
label whatever:
menu:
"What is the gender of your spouse ?"
"Female":
$ mcSpouseGender = "Female"
"Male":
$ mcSpouseGender = "Male"