Skip to content

Conditional Branch ​

Category: Flow Control (Flow)

An Event Content that evaluates a condition with a Formula and executes the inner processing only when true. Used together with Else / End If to implement the if-else-endif structure familiar from programming.

Always use with "End If" as a pair

When you use this event content, a corresponding End If is required. The placement structure looks like this:

Conditional Branch (Formula)
    (processing executed when true)
Else                       ← optional
    (processing executed when false)
End If                     ← required

Else is optional. If there is no Else, nothing is executed when false and the flow proceeds past End If.

Property List ​

Item (tscn label)Input FormatDescription
FormulaFormulaFormula for the condition (treated as always true if blank)
Template SelectSelect (helper)Insert a frequently used Formula sample in one click (editor helper, not saved)

Property Details ​

Formula ​

Specifies the Formula used for the condition. If the result is truthy (non-zero) it is treated as true; if falsy (zero) it is treated as false.

  • Blank: Always true (unconditionally executes the true side)
  • Formula: Evaluated with Formula.calc_bool; if truthy go to the true side, if falsy go to the false side

Variables and reference tokens can be used in Formulas

  • {counter_1} >= 10 — Variable counter_1 is at least 10
  • LOCAL.A — Local flag A is ON
  • not LOCAL.A — Local flag A is OFF
  • PARTY.GOLD >= 100 — Party gold is at least 100
  • MEM_0.HP.RATE < 0.3 — Leader's HP ratio is below 30%
  • MEMS_AVG.LEVEL.MAX >= 10 — Party average level is at least 10
  • LOCAL.A and LOCAL.B — Both local flags A and B are ON
  • {counter_1} >= 5 and {counter_1} <= 10 — Counter is within 5-10

For detailed Formula notation, see the Formula Reference.

Template Select (editor helper) ​

A dropdown menu that lets you insert frequently used Formula samples in one click.

14 provided templates:

Template NameFormula
Local flag A is ONLOCAL.A
Local flag A is OFFnot LOCAL.A
Variable >= value{counter_1} >= 10
Variable == value{flag_1} == 1
Variable < value{counter_1} < 5
Party gold >= valuePARTY.GOLD >= 100
Party avg level >= valueMEMS_AVG.LEVEL.MAX >= 10
Party max level >= valueMEMS_MAX.LEVEL.MAX >= 10
Leader HP rate < valueMEM_0.HP.RATE < 0.3
Leader HP now >= valueMEM_0.HP.NOW >= 100
Party count >= valueMEMS.COUNT >= 3
Local flag A and BLOCAL.A and LOCAL.B
Local flag A or BLOCAL.A or LOCAL.B
Variable in range{counter_1} >= 5 and {counter_1} <= 10

Templates are just samples

The Variable IDs (such as counter_1) and Parameter IDs (such as LEVEL, HP, GOLD) in each template match the sample data. You will need to rewrite them to the Variable IDs and Parameter IDs actually used in your own project.

After selecting a template, the Formula field is overwritten automatically. Please modify it by hand.

Runtime Behavior ​

When this event content is executed, the following processing is performed:

1. Formula Evaluation ​

  • Formula blank: Result is always true (unconditionally executes the true side)
  • Formula specified: Variables and reference tokens are expanded via Formula.replace_all(), then evaluated as bool via Formula.calc_bool()
    • Truthy (non-zero): true side
    • Falsy (zero): false side

2. When true ​

Execution continues sequentially from the line after this event content. When Else is reached, Else performs "skip all the way to the matching End If", so the processing after Else is not executed.

3. When false ​

Starting from this event content, scanning proceeds downward to find the corresponding Else or End If.

  • Else is found first: Execution starts from the line immediately after Else (Else itself is not executed)
  • End If is found first: Execution starts from the line immediately after End If

4. Nesting Support (K79 fixed 2026-09-02) ​

You can nest another Conditional Branch inside a Conditional Branch. The internal processing (_find_matching_end_forward) tracks depth so that an inner Conditional Branch's Else/End If is not confused with an outer one.

5. When no matching End If/Else is found ​

A warning log for developers is output:

[Event] Conditional Branch: matching End If/Else not found at line N, silent skip

The behavior is to silently proceed to the next event content (no error is raised). The log exists so that users can notice when they have forgotten an End If.

Typical Usage Flows ​

Flow 1: Simple Branching by Flag ​

Change the dialogue depending on whether a flag is set:

  1. Conditional Branch (this event content) (Formula {flag_boss_defeated} == 1)
  2. Show Text ← "Since you have defeated the boss..."
  3. Else
  4. Show Text ← "First, please defeat the boss."
  5. End If

Flow 2: Simple Branching without Else ​

Special processing only when the condition is met:

  1. Conditional Branch (this event content) (Formula {counter_rare_item} >= 5)
  2. Show Text ← "You've collected lots of rare items!"
  3. End If
  4. Show Text ← Common follow-up (executed regardless of condition)

Flow 3: Level-based Branching ​

Change enemy strength based on the party's level:

  1. Conditional Branch (this event content) (Formula MEMS_AVG.LEVEL.MAX >= 20)
  2. Show Text ← "A powerful enemy appears!"
  3. (strong enemy battle)
  4. Else
  5. Show Text ← "A weak enemy appears."
  6. (weak enemy battle)
  7. End If

Flow 4: Nested Conditional Branches ​

Combining multiple conditions (combining them into one Formula with and/or is more concise, but useful when you want to split the processing):

  1. Conditional Branch (this event content) (Formula LOCAL.A) ← outer: flag A
  2. Show Text ← "A processing begins"
  3. Conditional Branch (this event content) (Formula LOCAL.B) ← inner: flag B
  4. Show Text ← "Both A and B are ON"
  5. Else ← inner Else
  6. Show Text ← "Only A is ON"
  7. End If ← inner End If
  8. Else ← outer Else
  9. Show Text ← "A is OFF"
  10. End If ← outer End If

Flow 5: Multiple Conditions in One Line (and / or) ​

Written with and/or instead of nesting:

  1. Conditional Branch (this event content) (Formula LOCAL.A and LOCAL.B)
  2. Show Text ← "Both A and B are ON"
  3. End If

Flow 6: Range Check ​

Check whether a Variable is within a specific range:

  1. Conditional Branch (this event content) (Formula {counter} >= 5 and {counter} <= 10)
  2. Show Text ← "The counter is in the range 5-10"
  3. End If

Flow 7: Staging Based on HP Remaining ​

Special staging only when HP is low:

  1. Conditional Branch (this event content) (Formula MEM_0.HP.RATE < 0.3)
  2. Shake Screen (intensity 20, Pitch (quick))
  3. Show Text ← "I'm at my limit...!"
  4. End If

Flow 8: Choice Restriction by Gold ​

Check gold before purchase:

  1. Conditional Branch (this event content) (Formula PARTY.GOLD >= 100)
  2. Show Text ← "You can purchase it."
  3. (purchase processing)
  4. Else
  5. Show Text ← "Not enough money."
  6. End If

Typical Combinations ​

For the overall picture, see the Combination Patterns.

if-else-endif Pattern ​

The most basic branching structure:

  1. Conditional Branch (this event content) (condition)
  2. (processing when true)
  3. Else
  4. (processing when false)
  5. End If

Else-omitted Pattern ​

Processing only when the condition is met:

  1. Conditional Branch (this event content) (condition)
  2. (processing only when true)
  3. End If
  4. (common follow-up processing)

Branching on Choice Result (branch right after a choice) ​

Save the result to a Variable with Add Choice + Show Selection Window, then branch with this event content:

  1. Add Choice × 2
  2. Show Selection Window
  3. Conditional Branch (this event content) (Formula {selected} == 0)
  4. (processing when the 0th choice is selected)
  5. End If

Choosing between this and Move to Event ​

  • This event content: Branch processing within the same event
  • Move to Event: Conditional transition to another event, or jump to a label within the same event

For small branches use this event content; for separating a large block of processing into another event, Move to Event is more suitable.

Related Event ContentPurpose
ElseProcessing block for the false side (optional)
End IfMarker that indicates the end of the branch (required)
Move to EventTransition to another event / label via Formula check (used in contrast with this event content)
Assign VariableSet a Variable used in the condition check
PageRelated Content
Formula ReferenceFormula notation
Variable TabDefinition of Variables used in condition checks
Event Content ListList of all event contents

Notes ​

A matching "End If" is required ​

When you place this event content, you must also place the corresponding End If in the event. Without End If, processing continues into unintended places and a warning log is emitted (since the game silently proceeds, it does not stop, but the behavior becomes unclear).

Blank Formula is always true ​

If you leave the Formula blank, the result is always true. The behavior effectively becomes "unconditionally execute the true side", so be careful not to forget to write the intended condition.

Templates are samples ​

Formulas inserted via Template Select contain Variable IDs and Parameter IDs that match the sample data. You should replace them with the IDs of your own project before use.

Nesting is allowed (fixed 2026-09-02) ​

This event content can be nested. The inner/outer correspondence is detected correctly and automatically. However, deep nesting hurts readability, so for two or more levels of nesting consider restructuring or splitting it out into a sub-event (Move to Event + Return to Last Event).

Else is optional ​

If you omit Else, nothing is executed when false and the flow proceeds to the line right after End If. Else is not needed for the "special processing only when the condition is met" case.

When no matching End If/Else is found, behavior is silent ​

If no corresponding marker is found (because you forgot End If, for example), a warning log is emitted and the flow silently proceeds to the next event content. The game does not stop, but the behavior will not match your intent, so check the placement of End If in the editor.