-
Notifications
You must be signed in to change notification settings - Fork 1
Flags
Flags are Boolean values. Designed to have no problems with incompatibility of saves.
A good use is for example in quests to know quickly if MC has the possibility to do a certain thing, after unlocking it somehow.
By default, values are false.
INFO: For don't create problems if you not implement this in your project, the flags are not defined by default empty. BUT not save the changes.
For implement this you need to add this in your project:
default flags = { # You can enhance the flag during the first (it is not recommended)
}
define flag_keys = [ # All flags must be defined here
]
If you want to add a flag you need to add it in flags
.
If you set a flag true by default you can add it in flag_keys
.
for example:
default flags = { # You can enhance the flag during the first (it is not recommended)
"test2": True # it is not recommended
}
define flag_keys = [ # All flags must be defined here
"test1", # false
"test2", # true
]
For improve delete the expired flags after a update you need to add this in core.rpy
:
label after_load:
# renpy-utility-lib
$ update_flags()
Get the value of a flag.
$ get_flags("test1")
Set the value of a flag.
$ set_flags("test1", True)
The reason for this solution is that I needed to set flags in defined objects.
The following example helps me to make you understand.
class Button:
def __init__(
self,
id: #.....
disabled: Union[bool, str] = False,
):
self.disabled= disabled
# ...
def is_disabled(self, flags: dict[str, bool] = {}) -> bool:
""""If disabled is a string: get the value of the flags system"""
if (isinstance(self.disabled, str)):
return get_flags(self.disabled, flags)
else:
return self.disabled
# ❌ Since it is defined with define this variable will not be able to be changed during execution. I cannot enable the button.
# ✅ However, since it is a constant I can not worry about saving different versions. I can change the value of id as I want.
define button = Button(id = "1", disabled = true)
# ✅ I can enable the button.
# ✅ However, since it is a constant I can not worry about saving different versions. I can change the value of id as I want.
define flag_keys = [
"disabled_1"
]
define button = Button(id = "1", disabled = "disabled_1")
$ set_flags("disabled_1", True)
$ value = button.is_disabled(flags)