Loop End
Category: Flow Control (Flow)
Event content that marks the end of a Loop (Loop) and causes the loop to continue when this event content is reached (returning to just after Loop Start). It represents the "repetition point" of iterative processing.
Loop End is "continue the loop", Break Loop is "exit the loop"
Note the difference in role between this event content and Break Loop (Break Loop):
| Function | Behavior |
|---|---|
| Loop End (this event content) | Returns to just after Loop (Loop) (continues the iteration) |
| Break Loop (Break Loop) | Jumps to just after this event content (exits the loop) |
Property List
This event content has no properties. It operates simply by being added to the event content list.
Runtime Behavior
When this event content is executed, the following processing is performed:
1. Find the corresponding Loop
Scans upward from the position of this event content to find the corresponding Loop (Loop).
2. Jump to just after Loop
If the corresponding Loop (Loop) is found, jumps to the line immediately after it to continue the loop.
3. Yield 1 frame (stack overflow prevention)
Before returning to the loop, yields processing for 1 frame (await get_tree().process_frame). This:
- Prevents stack overflow from continuous synchronous recursive calls
- Even when there is no wait-type processing internally, the loop runs at most once per frame, preventing runaway behavior
4. Nesting support
When Loop (Loop) is nested, this event content corresponds to the innermost loop. Depth tracking ensures that it never returns to the wrong corresponding loop.
5. When no corresponding Loop is found
A developer-oriented warning log is output, and processing proceeds to the next event content without doing anything (silent fallback).
[Event] Loop End: matching Loop not found at line N, jumping to next lineChecks at Save Time (Important)
When saving an event in the editor, the following two types of validation are performed:
1. Presence of corresponding Loop
If this event content is placed without a Loop (Loop), an error is reported:
line N: Loop End が Loop なしで存在2. Presence of wait-type processing
If none of the following "wait-type processing" is included between Loop (Loop) and this event content, an error is reported as a risk of an infinite synchronous loop:
line N: Loop (line M 起点) 内に 待機系の処理 が無い (無限同期ループの危険)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 Wait even for intentional infinite loops like title screen demos
Even for intentional infinite loops like title screen demo playback, be sure to include Wait (Wait) or text display inside the loop. This event content yields 1 frame, but excessive continuous execution causes CPU load.
Typical Usage Flows
Flow 1: Minimum configuration (demo playback including Wait)
The simplest configuration that includes one wait-type processing in the loop:
- Loop (Loop)
- Show Image (Show Image) (number 0, image 1)
- Wait (Wait) (time 3.0) ← wait-type
- Show Image (Show Image) (number 0, image 2)
- Wait (Wait) (time 3.0)
- Loop End (this event content) ← returns to 1
Flow 2: Conditional termination loop (while-like)
Repeat until a condition is met, exit with Break Loop:
- Loop (Loop)
- Conditional Branch (Conditional Branch) (Formula
MEM_0.HP.NOW <= 0) - Break Loop (Break Loop) ← exits if condition met
- End If (End If)
- (loop body processing)
- Show Text (Show Text) ← wait-type
- Loop End (this event content)
Flow 3: Counter-based loop (for-like)
Repeat 5 times:
- Assign Variable (Assign Variable) (counter = 0)
- Loop (Loop)
- Conditional Branch (Conditional Branch) (Formula
{counter} >= 5) - Break Loop (Break Loop)
- End If (End If)
- Show Text (Show Text) ← message inside the loop
- Assign Variable (Assign Variable) (counter + 1)
- Loop End (this event content)
Flow 4: Menu display loop
Repeatedly display the menu until the user selects "quit":
- Loop (Loop)
- Show Window (Show Window)
- 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)
- End If (End If)
- (buy/sell processing)
- Loop End (this event content)
Flow 5: Nested loops
Multi-level loops (3 × 3 grid processing):
- Assign Variable (Assign Variable) (row = 0)
- Loop (Loop) ← outer
- Assign Variable (Assign Variable) (col = 0)
- Loop (Loop) ← inner
- (processing)
- Wait (Wait) (time 0.1) ← wait-type
- 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 (this event content) ← inner Loop End, returns to inner Loop
- 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 (this event content) ← outer Loop End, returns to outer Loop
Flow 6: Repeated playback of animation
Continuously play an animation in an infinite loop:
- Loop (Loop)
- Play Sound (Play Sound) (SOUND, sound effect)
- Shake Screen (Shake Screen) (strength 10, time 0.5, wait ON)
- Wait (Wait) (time 2.0) ← interval
- Loop End (this event content)
Typical Combinations
See Combination Pattern Collection for the overall picture.
Minimum configuration (infinite loop style)
Loop continuation:
- Loop (Loop)
- (loop body, including wait-type)
- Loop End (this event content)
Conditional termination loop
Exit with Break Loop:
- Loop (Loop)
- Conditional Branch (Conditional Branch) + Break Loop
- (loop body)
- Loop End (this event content)
Counter-based loop
Repeat a specified number of times using a variable:
- Assign Variable (Assign Variable) (variable initialization)
- Loop (Loop)
- Conditional Branch (Conditional Branch) + Break Loop (counter check)
- (loop body)
- Assign Variable (Assign Variable) (counter update)
- Loop End (this event content)
Nested loops
Multi-level loops:
- Loop (Loop) ← outer
- Loop (Loop) ← inner
- (inner processing + inner termination check)
- Loop End (this event content) ← inner
- (outer termination check)
- Loop End (this event content) ← outer
Related Event Contents
| Related Event Content | Purpose |
|---|---|
| Loop (Loop) | Pair with this event content (loop start, required pair) |
| Break Loop (Break Loop) | Exit the loop midway (role differs from this event content) |
| Conditional Branch (Conditional Branch) | Often used together for loop termination check |
| Wait (Wait) | Representative example of wait-type processing inside loop |
Related Pages
| Page | Related Content |
|---|---|
| Event Content List | List of all event contents |
Notes
Always place in pair with Loop
This event content is required as a set with Loop (Loop). After placing Loop (Loop), always place a corresponding instance of this event content. If you save an event without a corresponding pair, an error will occur at save time in the editor.
Wait-type processing required inside the loop
Between Loop (Loop) and this event content, be sure to include at least one wait-type processing that takes 1 frame or more, such as Wait (Wait) or Show Text (Show Text). If there is no wait-type processing, an error is reported at save time (to prevent the risk of infinite synchronous loops).
Difference between Loop End and Break Loop
- Loop End (this event content): Returns to the corresponding Loop (Loop) to continue the loop
- Break Loop (Break Loop): Proceeds to the line after the corresponding instance of this event content to exit the loop
Use Break Loop to exit the loop.
Automatic 1-frame yield
This event content internally yields 1 frame of processing. This ensures that even without wait-type processing, frames advance, so the game will not completely freeze. However, including wait-type processing inside the loop is recommended to reduce CPU load.
Nesting possible
When Loop (Loop) is nested, this event content corresponds to the innermost loop. The correspondence is correctly determined through depth tracking.
When no corresponding Loop is found
Outputs a warning log and proceeds to the next event content without doing anything (silent fallback). This case does not occur if validation on the editor side is in place, but is a safety measure for cases such as event data being broken by manual editing.
