Skip to content

Commit 5f30a56

Browse files
committed
note on a loop
1 parent cba194c commit 5f30a56

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/content/docs/ch02/03-while.mdx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Understanding WHILE loops in CLEO scripts
44
slug: while
55
---
66

7-
Many things in the game are extended in time or depend on the player feedback. A car driving to a destination, a model file loading from the disk, a button awaiting to be pressed all require a specific condition to become true. Did the car reach the point, was the specific button pressed, is the model available for use? If not, wait and check again later.
7+
Many things in the game are extended in time or depend on the player feedback. A car driving to a destination, a model file loading from the disk, a button awaiting to be pressed all require a specific condition to become true. Did the car reach the point, was the specific button pressed, is the model available for use? If not, wait and check again later.
88

99
We can validate certain condition continuously, each frame, or with some delay. To achieve this in the code, a special construct exists: a loop.
1010

@@ -26,7 +26,7 @@ end
2626
terminate_this_script
2727
```
2828

29-
The `wait 0` command is used to yield the execution for a frame, allowing the game to process other events and not freeze. It is crucial to have a `wait` command inside the loop body.
29+
The `wait 0` command is used to yield the execution for a frame, allowing the game to process other events and not freeze. It is crucial to have a `wait` command inside the loop body.
3030

3131
Once the condition becomes false, the loop stops and the execution moves to `terminate_this_script` command.
3232

@@ -39,3 +39,19 @@ end
3939
```
4040

4141
The script will be continuously checking if the model 42 is available, processing other game events between iterations.
42+
43+
:::note
44+
The script can't start with a loop. You need to have at least one instruction, for example `nop`, before any loop.
45+
46+
```sb
47+
{$CLEO}
48+
nop
49+
50+
while <condition>
51+
<block of code>
52+
end
53+
54+
terminate_this_script
55+
```
56+
57+
:::

0 commit comments

Comments
 (0)