LogoPixi’VN

Flags Management

Explains how to use boolean flags in Pixi'VN to control game flow and manage state efficiently.

Pixi’VN provides functions to manage "game flags". Game flags are boolean values used to control the flow of the game or to store other boolean state in the game storage.

This mechanic has much less impact on save size than directly saving a boolean in Game Storage.

Set

To set a flag, use the storage.setFlag function. Questa funzione ha i seguenti parametri:

  • name: The flag name.
  • value: The flag value.
import { storage } from '@drincs/pixi-vn'

storage.setFlag('flag1', true)

Ottieni

To get a flag, use the storage.getFlag function. Questa funzione ha i seguenti parametri:

  • name: The flag name.
import { storage } from '@drincs/pixi-vn'

const flag1 = storage.getFlag('flag1')

Possibilità di sviluppo

Connect a flag to a class boolean property

If you are creating a class with a boolean property, you can connect it to a flag. This way, the property will automatically reflect the flag's value.

This can simplify your code and make it more readable.

import { storage } from '@drincs/pixi-vn'

class ButtonClass {
    private _disabled: boolean | string
    get disabled() {
        if (typeof this._disabled === 'string') {
            return storage.getFlag(this._disabled)
        }
        return this._disabled
    }
    set disabled(value: boolean | string) {
        this._disabled = value
    }
}
// Button to go to school
const goToSchoolButton = new ButtonClass()
goToSchoolButton.disabled = 'weekend'

function afterNewDay() {
    storage.setFlag('weekend', 
        // Check if it is Saturday or Sunday
    )
}