Skip to content

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):

FunctionBehavior
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 line

Checks 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:

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:

  1. Loop (Loop)
  2. Show Image (Show Image) (number 0, image 1)
  3. Wait (Wait) (time 3.0) ← wait-type
  4. Show Image (Show Image) (number 0, image 2)
  5. Wait (Wait) (time 3.0)
  6. 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:

  1. Loop (Loop)
  2. Conditional Branch (Conditional Branch) (Formula MEM_0.HP.NOW <= 0)
  3. Break Loop (Break Loop) ← exits if condition met
  4. End If (End If)
  5. (loop body processing)
  6. Show Text (Show Text) ← wait-type
  7. Loop End (this event content)

Flow 3: Counter-based loop (for-like) ​

Repeat 5 times:

  1. Assign Variable (Assign Variable) (counter = 0)
  2. Loop (Loop)
  3. Conditional Branch (Conditional Branch) (Formula {counter} >= 5)
  4. Break Loop (Break Loop)
  5. End If (End If)
  6. Show Text (Show Text) ← message inside the loop
  7. Assign Variable (Assign Variable) (counter + 1)
  8. Loop End (this event content)

Flow 4: Menu display loop ​

Repeatedly display the menu until the user selects "quit":

  1. Loop (Loop)
  2. Show Window (Show Window)
  3. Add Choice (Add Choice) × 3 (buy / sell / quit)
  4. Show Selection Window (Show Selection Window)
  5. Conditional Branch (Conditional Branch) (Formula {selected} == 2)
  6. Break Loop (Break Loop)
  7. End If (End If)
  8. (buy/sell processing)
  9. Loop End (this event content)

Flow 5: Nested loops ​

Multi-level loops (3 × 3 grid processing):

  1. Assign Variable (Assign Variable) (row = 0)
  2. Loop (Loop) ← outer
  3. Assign Variable (Assign Variable) (col = 0)
  4. Loop (Loop) ← inner
  5. (processing)
  6. Wait (Wait) (time 0.1) ← wait-type
  7. Assign Variable (Assign Variable) (col + 1)
  8. Conditional Branch (Conditional Branch) (Formula {col} >= 3)
  9. Break Loop (Break Loop) ← inner Break
  10. End If (End If)
  11. Loop End (this event content) ← inner Loop End, returns to inner Loop
  12. Assign Variable (Assign Variable) (row + 1)
  13. Conditional Branch (Conditional Branch) (Formula {row} >= 3)
  14. Break Loop (Break Loop) ← outer Break
  15. End If (End If)
  16. 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:

  1. Loop (Loop)
  2. Play Sound (Play Sound) (SOUND, sound effect)
  3. Shake Screen (Shake Screen) (strength 10, time 0.5, wait ON)
  4. Wait (Wait) (time 2.0) ← interval
  5. Loop End (this event content)

Typical Combinations ​

See Combination Pattern Collection for the overall picture.

Minimum configuration (infinite loop style) ​

Loop continuation:

  1. Loop (Loop)
  2. (loop body, including wait-type)
  3. Loop End (this event content)

Conditional termination loop ​

Exit with Break Loop:

  1. Loop (Loop)
  2. Conditional Branch (Conditional Branch) + Break Loop
  3. (loop body)
  4. Loop End (this event content)

Counter-based loop ​

Repeat a specified number of times using a variable:

  1. Assign Variable (Assign Variable) (variable initialization)
  2. Loop (Loop)
  3. Conditional Branch (Conditional Branch) + Break Loop (counter check)
  4. (loop body)
  5. Assign Variable (Assign Variable) (counter update)
  6. Loop End (this event content)

Nested loops ​

Multi-level loops:

  1. Loop (Loop) ← outer
  2. Loop (Loop) ← inner
  3. (inner processing + inner termination check)
  4. Loop End (this event content) ← inner
  5. (outer termination check)
  6. Loop End (this event content) ← outer
Related Event ContentPurpose
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
PageRelated Content
Event Content ListList 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.