This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| crpl:docs:if [2013/01/14 19:04] – created virgilw | crpl:docs:if [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | TODO | + | <- [[crpl: |
| + | ===== if ===== | ||
| + | |||
| + | ^Arguments^Result^Notation^ | ||
| + | |Cond| |'' | ||
| + | |||
| + | |||
| + | === Description === | ||
| + | Evaluate the first element on the stack. | ||
| + | If True, then execute statements that follow, up to the endif or else statement. | ||
| + | If False, execution skips to the first statement following the endif or else statement. | ||
| + | Any nonzero value is consierered True, a value of zero is False. | ||
| + | === Examples === | ||
| + | < | ||
| + | # Creates a runner at the units current coordinates | ||
| + | # every three seconds, but only if there is digitalis underneath. | ||
| + | CurrentCoords GetDigitalis if | ||
| + | CurrentCoords 2 10 20 CreateRunner | ||
| + | 90 Delay | ||
| + | endif | ||
| + | </ | ||
| + | < | ||
| + | # Pick a random integer between 0(inclusive) and 100(exclusive). | ||
| + | # If the random number is less than 95 emit 10 Creeper, | ||
| + | # otherwise emit 100 Creeper. | ||
| + | 0 100 RandInt 95 lt if | ||
| + | CurrentCoords 10 AddCreeper | ||
| + | else | ||
| + | CurrentCoords 100 AddCreeper | ||
| + | endif | ||
| + | </ | ||