Loop
Category: Flow Control (Flow)
A marker indicating the starting point of iterative (loop) processing. The processing written between this event content and Loop End (Loop End) is executed repeatedly until a Break Loop (Break Loop) or a conditional termination occurs.
Always place with Loop End as a pair
When using this event content, always place a corresponding Loop End (Loop End). Structure of placement:
Loop (this event content)
(processing executed repeatedly)
[Conditional Branch → Break Loop for termination check]
Loop End (Loop End) ← requiredTo exit the loop midway, combine Conditional Branch (Conditional Branch) + Break Loop (Break Loop).
Always include "wait-type processing" in the loop to avoid infinite loops
At editor save time, if none of the following "wait-type processing" is included in the loop, an error is reported. This is validation to prevent an infinite loop without waiting that would freeze the game.
List of wait-type processing:
- Show Text (Show Text)
- Wait (Wait)
- Show Window (Show Window)
- Show Selection Window (Show Selection Window)
- Show Item Select (Show Item Select)
- Show Number Input (Show Number Input)
- Show Text Input (Show Text Input)
- Start Battle (Start Battle)
- Show Shop Buy (Show Shop Buy)
- Show Shop Sell (Show Shop Sell)
- Move to Event (Move to Event)
- Return to Last Event (Return to Last Event)
Include at least one of these in the loop.
Property List
This event content has no properties. It operates simply by being added to the event content list.
Runtime Behavior
This event content is an entry marker. At runtime, it does nothing and immediately proceeds to the next event content.
1. Reaching the entry
When this event content is reached: Does nothing and starts executing the next event content.
2. Execution of the loop body
The event contents between this and Loop End (Loop End) are executed sequentially.
3. Reaching Loop End
When the Loop End (Loop End) at the end of the loop body is reached, the corresponding instance of this event content is found, and processing jumps to the line immediately after it to continue the loop. One frame is yielded before resumption, preventing stack overflow.
4. Methods for terminating the loop
There are two methods for terminating the loop:
- Break Loop (Break Loop): Jumps to just after the corresponding Loop End (Loop End) and exits the loop
- Move to Event (Move to Event) jumps outside the loop: forced exit
5. Nesting support
This event content can be nested. The correspondence (Loop ↔ Loop End) between inner and outer loops is automatically determined correctly (depth tracking).
Break Loop (Break Loop) exits the nearest instance of this event content (exits the inner loop while remaining in the outer loop).
Typical Usage Flows
Flow 1: Repetition using a counter
Repeat a specified number of times using a variable:
- Assign Variable (Assign Variable) (counter = 0)
- Loop (this event content)
- Show Text (Show Text) ← processing inside the loop
- Assign Variable (Assign Variable) (counter + 1)
- Conditional Branch (Conditional Branch) (Formula
{counter} >= 5) - Break Loop (Break Loop) ← exits after 5 iterations
- End If (End If)
- Loop End (Loop End)
Flow 2: Choice-based menu loop
Repeatedly display the menu until a selection is made:
- Loop (this event content)
- Show Window (Show Window)
- Show Text (Show Text) ← menu title
- Add Choice (Add Choice) × 3 (buy / sell / quit)
- Show Selection Window (Show Selection Window)
- Conditional Branch (Conditional Branch) (Formula
{selected} == 2) - Break Loop (Break Loop) ← exits when "quit" is selected
- End If (End If)
- (buy/sell processing)
- Loop End (Loop End)
Flow 3: Condition-based loop
Repeat until a certain state is reached:
- Loop (this event content)
- Conditional Branch (Conditional Branch) (Formula
MEM_0.HP.NOW <= 0) - Break Loop (Break Loop) ← exits when HP reaches 0
- End If (End If)
- (damage processing)
- Show Text (Show Text) ← damage line
- Loop End (Loop End)
Flow 4: Nested loops
Multi-level loops (3 × 3 grid processing, etc.):
- Assign Variable (Assign Variable) (row = 0)
- Loop (this event content) ← outer (row)
- Assign Variable (Assign Variable) (col = 0)
- Loop (this event content) ← inner (col)
- (per-col processing)
- Assign Variable (Assign Variable) (col + 1)
- Conditional Branch (Conditional Branch) (Formula
{col} >= 3) - Break Loop (Break Loop) ← inner Break
- End If (End If)
- Loop End (Loop End) ← inner Loop End
- Assign Variable (Assign Variable) (row + 1)
- Conditional Branch (Conditional Branch) (Formula
{row} >= 3) - Break Loop (Break Loop) ← outer Break
- End If (End If)
- Loop End (Loop End) ← outer Loop End
Flow 5: Infinite loop for demo playback
Continuously play title screen background demo:
- Loop (this event content)
- Show Image (Show Image) (number 0, image 1)
- Wait (Wait) (time 3.0) ← including wait-type avoids infinite synchronous loop
- Show Image (Show Image) (number 0, image 2)
- Wait (Wait) (time 3.0)
- Loop End (Loop End)
(Since the title screen transitions on user input, an infinite loop is not a problem in terms of game progression)
Flow 6: Sound playback → selection → repetition
Repeated check while playing sound:
- Play Sound (Play Sound) (BGM)
- Loop (this event content)
- Show Selection Window (Show Selection Window) ← wait-type
- (processing of selection result)
- Loop End (Loop End)
Typical Combinations
See Combination Pattern Collection for the overall picture.
Conditional termination loop (while-like)
Repeat until condition is met:
- Loop (this event content)
- Conditional Branch (Conditional Branch) (termination condition)
- Break Loop (Break Loop)
- End If (End If)
- (loop body)
- Loop End (Loop End)
Counter-based loop (for-like)
Repeat specified number of times:
- Assign Variable (Assign Variable) (variable initialization)
- Loop (this event content)
- Conditional Branch (Conditional Branch) (counter condition)
- Break Loop (Break Loop)
- End If (End If)
- (loop body)
- Assign Variable (Assign Variable) (counter update)
- Loop End (Loop End)
Menu display loop
Repeat menu until user selects "quit":
- Loop (this event content)
- Show Selection Window (Show Selection Window)
- Conditional Branch (Conditional Branch) ("quit" check)
- Break Loop (Break Loop)
- End If (End If)
- (processing of each choice)
- Loop End (Loop End)
Nested loops (multi-level loops)
Matrix processing, etc.:
- Loop (this event content) ← outer
- Loop (this event content) ← inner
- (processing)
- (inner termination check + Break Loop)
- Loop End (Loop End) ← inner
- (outer termination check + Break Loop)
- Loop End (Loop End) ← outer
Related Event Contents
| Related Event Content | Purpose |
|---|---|
| Loop End (Loop End) | Pair with this event content (end of loop body, required pair) |
| Break Loop (Break Loop) | Exit the loop midway |
| Conditional Branch (Conditional Branch) | Frequently used together for termination checks inside the loop |
| Else (Else) | Used together with Conditional Branch |
| End If (End If) | Used together with Conditional Branch |
| Wait (Wait) | Representative example of wait-type processing inside loop |
Related Pages
| Page | Related Content |
|---|---|
| Formula Reference | Formulas for loop termination checks |
| Variable Tab | Definition of counter variables |
| Event Content List | List of all event contents |
Notes
Loop End is required
When this event content is placed, always place a corresponding Loop End (Loop End). Without a corresponding pair, an error occurs at editor save time.
Infinite loop prevention (Important)
If this event content is used without including any wait-type processing (see the tip above for details) in the loop, an "infinite synchronous loop risk" error occurs at editor save time. This is validation to prevent the game from freezing in an infinite loop without waiting.
Be sure to include processing that takes 1 frame or more in the loop, such as Wait (Wait) or Show Text (Show Text).
Implement termination check yourself to exit the loop
This event content does not have a built-in loop termination function. You need to implement the termination check yourself with Conditional Branch (Conditional Branch) + Break Loop (Break Loop).
Nesting possible
This event content can be nested. An inner Break Loop exits only the inner loop (does not affect the outer loop).
Manually manage counter variables
There is no counter auto-management feature like for loops. Explicitly increment the counter with Assign Variable (Assign Variable).
As an entry marker, does nothing at runtime
This event content does nothing at runtime and immediately proceeds to the next event content. Its actual role is to serve as a marker indicating the "starting point of the loop" for the runtime to reference.
