Conditionals

Control the flow of your game based on conditions

Description

{'Conditional': {
    'Condition': function() { /* return true/false or string */ },
    'True': '<statement>',
    'False': '<statement>'
}}

Conditionals allow you to control the flow of your game based on conditions. You can show different dialogs, jump to different labels, or execute different actions depending on storage values, player choices, or any other condition.

Action ID: Conditional

Reversible: Yes

Requires User Interaction: Depends on the branch statement executed

Basic Structure

Property
Type
Description

Condition

function

Function that returns true, false, or a string key

True

statement

Statement to execute if condition returns true

False

statement

Statement to execute if condition returns false

<custom>

statement

Custom branches when using string return values

Examples

Boolean Condition

Check if a condition is true or false:

Conditional Jump

Jump to different labels based on a condition:

Multiple Branches (String Returns)

Use string return values for more than two branches:

Numeric String Branches

Use numbers as string keys for indexed branches:

Complex Condition

Combine multiple checks:

Important Notes

[!WARNING] All branches must be defined! Monogatari throws an error if the Condition returns a value that doesn't match any branch key. Always account for all possible return values.

String vs Boolean

  • Return true → executes 'True' branch

  • Return false → executes 'False' branch

  • Return 'someString' → executes 'someString' branch

Numbers as Keys

Numbers cannot be used directly as object keys. Convert to strings:

Async Conditions

Conditions can use Promises for async operations:

Rollback Behavior

Conditionals support rollback. When the player goes back:

  • The previously executed branch is reverted

  • The condition is re-evaluated on the next forward progression

  • Jump - Navigate to different labels

  • Choices - Let players choose branches

  • Functions - Run JavaScript code

Last updated

Was this helpful?