Skip to content
Black Ram edited this page Sep 21, 2023 · 17 revisions

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.

Usage

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:

define flag_keys = [ # All flags must be defined here
]

If you want to add a flag you need to add it in flag_keys.

for example:

define flag_keys = [ # All flags must be defined here
    "test1", # false
]

For improve delete the expired flags after a update

For improve delete the expired flags after a update you need to add this in core.rpy:

label after_load:
    # renpy-utility-lib
    call update_current_flags(update_dictionary = True)

Get

Get the value of a flag.

$ get_flags("test1")

Set

Set the value of a flag.

$ set_flags("test1", True)

update_current_flags

For improve the update of the current flags I added a function for update the flags.

If you added a label called update_current_flags in your project, this will be used to update flags from other libraries that use this project.

Example:

label update_current_flags
    # check if today is a weekend
    if today in ["Saturday", "Sunday"]:
        $ set_flags("weekend", True)
    else:
        $ set_flags("weekend", False)
    return

Development possibilities

Ability to edit flags in constants

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

Problem

# ❌ 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)

Solution

# ✅ 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)