Skip to content

Commit 0149270

Browse files
authored
while true
1 parent e437217 commit 0149270

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

content/while-true.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
TBD
1+
`while true` is an infinite loop. It ends only with the `break` command or when the script is ended (e.g. using `terminate_this_script`).
2+
3+
It is often used to create a main body of a CLEO script, which contantly awaits for a key press to trigger some action.
4+
5+
```
6+
while true
7+
wait 0
8+
if
9+
is_key_pressed 113 // F2
10+
then
11+
break
12+
end
13+
14+
add_score {player} 0 {money} 10
15+
end
16+
terminate_this_script
17+
```
18+
19+
This loop adds $1 to the player's account each frame until the F2 button is pressed to exit the loop. Note that after breaking from the loop, the script continues to the next command, which is `terminate_this_script`.
20+

content/while.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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 reached the point, was the specific button pressed, is the model available for use? If not, wait and check again later.
1+
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.
22

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

0 commit comments

Comments
 (0)