Variables
Variables store data that persists throughout your story. Use them to track player options, inventory, stats, quest progress, and any other state that changes as the narrative unfolds.
Overview
Variables are a core component of StoryFlow's visual scripting system (also referred to as the node editor), allowing you to create dynamic, reactive stories that remember player actions and adapt based on their selections. You can get and set variable values without writing any code, enabling complex interactive narratives with branching paths, conditional dialogue, and stat-based gameplay.
What Variables Enable:
- Track whether the player has completed quests or talked to NPCs
- Store inventory items, health points, gold amounts, and other stats
- Create conditional dialogue that changes based on previous selections
- Build relationship systems, karma meters, and alignment tracking
- Share state between different script files using global variables
Key Concept
Variable Types
StoryFlow Editor supports two variable types: Boolean and Integer. Each type serves different purposes and has different node types for reading and writing values.
Boolean Variables
Visual Indicator: Boolean
Values: true or false
Purpose: Store yes/no, on/off, has/doesn't have states. Booleans are perfect for flags, switches, and binary conditions.
Common Examples:
- Boolean hasKey - Player has obtained the key
- Boolean talkedToGuard - Player has spoken with the guard
- Boolean questCompleted - Quest has been finished
- Boolean doorIsOpen - Door state
- Boolean playerIsAlive - Player alive status
- Boolean acceptedQuest - Player accepted a quest offer
Integer Variables
Visual Indicator: Integer
Values: Whole numbers (positive, negative, or zero)
Purpose: Store numeric data like counts, stats, scores, and quantities. Integers can be used in mathematical calculations and comparisons.
Common Examples:
- Integer playerHealth - Current hit points (e.g., 100)
- Integer goldAmount - Currency quantity (e.g., 500)
- Integer questProgress - Completion percentage (e.g., 3 out of 5)
- Integer relationshipLevel - NPC affection rating (-10 to +10)
- Integer enemiesDefeated - Kill count (e.g., 15)
- Integer daysPassed - In-game time tracking (e.g., 7)
| Feature | Boolean | Integer |
|---|---|---|
| Color | Boolean | Integer |
| Possible Values | true, false | ..., -2, -1, 0, 1, 2, ... |
| Default Value | false | 0 |
| Logic Nodes | And, Or, Not, Equal | >, >=, <, <=, ==, +, - |
| Use Cases | Flags, switches, states | Stats, counts, quantities |
Creating Variables
Variables are created and managed through the Variables Panel on the left side of the editor. The panel shows all variables for the current script file.
To Create a New Variable:
- Open a script file in the editor (variables belong to scripts)
- Look at the Variables Panel on the left sidebar
- Click the Add button (+) at the top of the panel
- A dropdown appears with two options: Boolean or Integer
- Select the type you need
- A new variable appears in the list with a default name (e.g., "NewVar0")
- Click the variable name to rename it to something descriptive
Naming Variables
- Boolean hasCompletedQuest (camelCase)
- Boolean has_completed_quest (snake_case)
- Boolean Has Completed Quest (with spaces)
- Integer playerGold (camelCase)
- Integer Player Gold (with spaces)
The key is to maintain consistency throughout your project and keep names descriptive. Good names make your logic self-documenting and easier to understand when you return to the project later.
Variable Panel Features:
- Variable List: Shows all variables for the current script
- Type Indicator: Boolean for boolean, Integer for integer
- Global Marker: icon appears next to global variables
- Count Badge: Header shows total number of variables
- Drag to Canvas: Drag a variable onto the canvas to quickly create Get/Set nodes
Local vs Global Variables
Variables in StoryFlow Editor can have two different scopes: Local (default) or Global. Understanding the difference is crucial for organizing multi-script projects.
Local Variables
Scope: Exist only within the current script file
Storage: Saved inside the .sfe script file
Lifespan: Reset to default values each time the script starts
Use Cases:
- Temporary state within a single scene or dialogue
- Loop counters and intermediate calculations
- Conversation-specific flags (e.g., Boolean askedAboutQuest in a merchant dialogue)
- Local options that don't need to persist (e.g., dialogue option tracking)
Example: A dialogue script for a merchant might have a local Boolean showSecretOption that tracks whether the player asked the right questions in that specific conversation. It doesn't need to be global because it's only relevant to that one dialogue tree.
Global Variables
Scope: Accessible from ALL script files in the project
Storage: Saved in global-variables.json at the project root
Lifespan: Persist across script transitions and play sessions
Visual Indicator: Globe icon next to the variable name
Use Cases:
- Player stats that persist throughout the game (health, gold, experience)
- Quest completion flags accessed from multiple scripts
- Inventory items that affect dialogue across different scenes
- Story progression flags (chapter completed, character met, etc.)
- Game-wide settings and unlocks
Example: A global Integer playerGold can be checked by a merchant script, modified by a quest reward script, and displayed in a status menu script. All scripts see the same value.
Converting to Global
To mark a variable as global:
- Right-click the variable in the Variables Panel
- Select "Make Global" from the context menu
- The variable is now global and will show a globe icon
Global Variable Considerations
Using Variables
Once you've created variables, you use them in your story through Get and Set nodes.
Reading Variables (Get Nodes)
Get nodes read the current value of a variable and output it through a data handle.
Creating a Get Node:
- Method 1: Drag a variable from the Variables Panel onto the canvas, then select "Get" from the menu
- Method 2: Right-click the canvas, navigate to the Variables section, and select the Get node for your variable
Common Pattern - Reading for Conditions:
- Create a Boolean Get node for Boolean hasKey
- Connect its output (yellow handle) to a Branch node's condition input
- The Branch will route to True if the player has the key, False otherwise
Writing Variables (Set Nodes)
Set nodes change a variable's value. They have both execution flow and data connections.
Set Node Features:
- Execution Input (top left): When to set the variable
- Value Input (bottom left): What value to set (can be connected or manually entered)
- Execution Output (top right): Continues story flow after setting
- Value Output (bottom right): Pass-through of the new value for chaining
Example - Setting a Boolean:
- Player clicks dialogue option "Take the key"
- Option output connects to execution input of Set Boolean node for Boolean hasKey
- Value input is set to
true(checkbox checked) - Variable Boolean hasKey is now true
- Execution continues to next dialogue
Example - Incrementing an Integer:
- Create Get Integer node for Integer playerGold
- Create a Plus node
- Connect Get node output to Plus node top input
- Set Plus node bottom input to 50 (reward amount)
- Create Set Integer node for Integer playerGold
- Connect Plus node output to Set node value input
- Connect execution flow through the Set node
- Result: Integer playerGold increases by 50
Conditional Dialogue Options
Dialogue nodes have optional condition inputs for each option. Connect a boolean handle to make an option appear only when the condition is true.
Example - Item-Gated Option:
- Create a Dialogue node with the option "Unlock the door"
- Create a Boolean Get node for Boolean hasKey
- Connect the Get node's output to the option's condition input (yellow handle on left)
- The "Unlock the door" option only appears if Boolean hasKey is true
Complex Conditions
Best Practices
Follow these guidelines to use variables effectively in your interactive narratives.
Naming Examples
You're free to name variables however you prefer. Here are some common patterns you might find useful:
- camelCase Example: Boolean hasCompletedQuest or
has_completed_quest - Descriptive Names: Boolean talkedToMerchant compared to Boolean flag1
- Boolean Prefixes: You can start booleans with
has,is,can,should - Integer Examples: Nouns for quantities ( Integer goldAmount , Integer healthPoints )
- Abbreviations: Boolean questCompleted vs Boolean qstCmpltd
Scope Management
- Default to Local: Only make variables global if they need to be shared
- Document Globals: Use Comment nodes to explain what global variables do
- Consistent Naming: Prefix globals with
globalif needed (e.g.,globalPlayerHealth) - Centralize Updates: Modify important globals in dedicated scripts to avoid conflicts
Initial Values
- Set Defaults: Initialize variables at the start of your project
- Use Start Script: Set global variable defaults in your startup script
- Document Ranges: Comment expected value ranges (e.g., health: 0-100)
Organization
- Group Related Variables: Keep variables for the same system together in the panel
- Clean Up Unused: Delete variables that are no longer needed
- Consistent Patterns: Use similar names for similar concepts (e.g.,
hasKey,hasSword,hasMap)
Variable Checklist
- Descriptive, meaningful names
- Correct type for the data (Boolean for flags, Integer for numbers)
- Appropriate scope (Local unless shared across scripts)
- Initial values set in startup script
- Used in Get/Set nodes appropriately
Common Patterns
Quest Tracking:
questAccepted, questCompleted
questProgress (e.g., 0-5 objectives) Inventory System:
hasKey, hasSword, hasPotion
potionCount, goldAmount Relationship System:
metCharacter, isAlly, isEnemy
relationshipLevel (-10 to +10) Player Stats:
health (0-100), mana (0-100), level (1-99) Next Steps