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 ← requiredElse 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 Format | Description |
|---|---|---|
| Formula | Formula | Formula for the condition (treated as always true if blank) |
| Template Select | Select (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— Variablecounter_1is at least 10LOCAL.A— Local flag A is ONnot LOCAL.A— Local flag A is OFFPARTY.GOLD >= 100— Party gold is at least 100MEM_0.HP.RATE < 0.3— Leader's HP ratio is below 30%MEMS_AVG.LEVEL.MAX >= 10— Party average level is at least 10LOCAL.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 Name | Formula |
|---|---|
| Local flag A is ON | LOCAL.A |
| Local flag A is OFF | not LOCAL.A |
| Variable >= value | {counter_1} >= 10 |
| Variable == value | {flag_1} == 1 |
| Variable < value | {counter_1} < 5 |
| Party gold >= value | PARTY.GOLD >= 100 |
| Party avg level >= value | MEMS_AVG.LEVEL.MAX >= 10 |
| Party max level >= value | MEMS_MAX.LEVEL.MAX >= 10 |
| Leader HP rate < value | MEM_0.HP.RATE < 0.3 |
| Leader HP now >= value | MEM_0.HP.NOW >= 100 |
| Party count >= value | MEMS.COUNT >= 3 |
| Local flag A and B | LOCAL.A and LOCAL.B |
| Local flag A or B | LOCAL.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 viaFormula.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 skipThe 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:
- Conditional Branch (this event content) (Formula
{flag_boss_defeated} == 1) - Show Text ← "Since you have defeated the boss..."
- Else
- Show Text ← "First, please defeat the boss."
- End If
Flow 2: Simple Branching without Else
Special processing only when the condition is met:
- Conditional Branch (this event content) (Formula
{counter_rare_item} >= 5) - Show Text ← "You've collected lots of rare items!"
- End If
- Show Text ← Common follow-up (executed regardless of condition)
Flow 3: Level-based Branching
Change enemy strength based on the party's level:
- Conditional Branch (this event content) (Formula
MEMS_AVG.LEVEL.MAX >= 20) - Show Text ← "A powerful enemy appears!"
- (strong enemy battle)
- Else
- Show Text ← "A weak enemy appears."
- (weak enemy battle)
- 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):
- Conditional Branch (this event content) (Formula
LOCAL.A) ← outer: flag A - Show Text ← "A processing begins"
- Conditional Branch (this event content) (Formula
LOCAL.B) ← inner: flag B - Show Text ← "Both A and B are ON"
- Else ← inner Else
- Show Text ← "Only A is ON"
- End If ← inner End If
- Else ← outer Else
- Show Text ← "A is OFF"
- End If ← outer End If
Flow 5: Multiple Conditions in One Line (and / or)
Written with and/or instead of nesting:
- Conditional Branch (this event content) (Formula
LOCAL.A and LOCAL.B) - Show Text ← "Both A and B are ON"
- End If
Flow 6: Range Check
Check whether a Variable is within a specific range:
- Conditional Branch (this event content) (Formula
{counter} >= 5 and {counter} <= 10) - Show Text ← "The counter is in the range 5-10"
- End If
Flow 7: Staging Based on HP Remaining
Special staging only when HP is low:
- Conditional Branch (this event content) (Formula
MEM_0.HP.RATE < 0.3) - Shake Screen (intensity 20, Pitch (quick))
- Show Text ← "I'm at my limit...!"
- End If
Flow 8: Choice Restriction by Gold
Check gold before purchase:
- Conditional Branch (this event content) (Formula
PARTY.GOLD >= 100) - Show Text ← "You can purchase it."
- (purchase processing)
- Else
- Show Text ← "Not enough money."
- End If
Typical Combinations
For the overall picture, see the Combination Patterns.
if-else-endif Pattern
The most basic branching structure:
- Conditional Branch (this event content) (condition)
- (processing when true)
- Else
- (processing when false)
- End If
Else-omitted Pattern
Processing only when the condition is met:
- Conditional Branch (this event content) (condition)
- (processing only when true)
- End If
- (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:
- Add Choice × 2
- Show Selection Window
- Conditional Branch (this event content) (Formula
{selected} == 0) - (processing when the 0th choice is selected)
- 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 Contents
| Related Event Content | Purpose |
|---|---|
| Else | Processing block for the false side (optional) |
| End If | Marker that indicates the end of the branch (required) |
| Move to Event | Transition to another event / label via Formula check (used in contrast with this event content) |
| Assign Variable | Set a Variable used in the condition check |
Related Pages
| Page | Related Content |
|---|---|
| Formula Reference | Formula notation |
| Variable Tab | Definition of Variables used in condition checks |
| Event Content List | List 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.
