Variables and Game State
Estimated reading time: 3 minutesThe Variables module manages the framework's data storage in the SugarCube2 save system, including the V.maplebirch namespace and V.options.maplebirch option configuration.
V.maplebirch Namespace
The framework uses V.maplebirch as a unified variable namespace to avoid conflicts with the base game and other Mods.
Default Variable Structure
When starting a new game (Start2 Passage), V.maplebirch is initialized as:
V.maplebirch.player.clothing is a read-only proxy for V.worn. Modifying it directly will trigger a warning; please use V.worn to modify player equipment.
V.options.maplebirch
Option configuration is stored in V.options.maplebirch and remains consistent across saves.
Default Options
Option Validation and Merge
The framework performs option validation on every :passageend and save load. The merge strategy is deep merge with type validation—if the value type in the save does not match the default, the default value will be used.
Variable Migration System
The Variables module integrates the migration utility to handle data migration during version upgrades.
Migration Trigger Timing
- New Game: Initialize default variables when the
Start2Passage runs - Every Passage: Check and run migrations during the
Init()phase - Save Load: Check and run migrations during the
loadInit()phase - Post-initialization: Run migrations again if version is inconsistent
Using Migration
Hair Colour Gradients
The Variables module provides the hairgradients() function to extract available hair colour gradient data from the game's setup.colours.hairgradients_prototypes:
This data is used for hair colour gradient configuration in the character rendering system.
