for (roll option): Difference between revisions
No edit summary |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 6: | Line 6: | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[for(var, start, end): body] | [for(var, start, end): body] | ||
</ | </syntaxhighlight> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[for(var, start, end, stepsize): body] | [for(var, start, end, stepsize): body] | ||
</ | </syntaxhighlight> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[for(var, start, end, stepsize, separator): body] | [for(var, start, end, stepsize, separator): body] | ||
</ | </syntaxhighlight> | ||
'''Parameters'''<br> | '''Parameters'''<br> | ||
The {{code|var}} variable counts from {{code|start}} towards {{code|end}} during the loop, and the optional {{code|stepsize}} (default {{code|+1}}) is added to {{code|var}} at each iteration. Note that in the standard incrementing usage with a {{code|stepsize}} of {{code|1}}, the {{code|body}} does not execute when {{code|var}} reaches {{code|end}}. <br> | The {{code|var}} variable counts from {{code|start}} towards {{code|end}} during the loop, and the optional {{code|stepsize}} (default {{code|+1}}) is added to {{code|var}} at each iteration. Note that in the standard incrementing usage with a {{code|stepsize}} of {{code|1}}, the {{code|body}} does not execute when {{code|var}} reaches {{code|end}}. <br> | ||
Note that {{code|stepsize}} must be integer and not 0. Floating values will be rounded down.<br> | Note that {{code|stepsize}} must be integer and not 0. Floating values will be rounded down.<br> | ||
{{code|list_separator}} default value is {{code|","}} | {{code|list_separator}} default value is {{code|","}}. Some examples of other useful separators: ''nothing'' {{code|""}}, ''space'' {{code|" "}} and ''break'' {{code|"<br>"}}. | ||
Some examples of other useful | |||
|examples= | |examples= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[for(i,0,10): "i is now " + i] | [for(i,0,10): "i is now " + i] | ||
</ | </syntaxhighlight> | ||
Counts up from 0 to 9. | Counts up from 0 to 9. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[for(i,10,0,-2): "i is now " + i] | [for(i,10,0,-2): "i is now " + i] | ||
</ | </syntaxhighlight> | ||
Counts down even numbers from 10 to 2. | |||
<syntaxhighlight lang="mtmacro" line> | |||
[for(i,10,-1,-2): "i is now " + i] | |||
</syntaxhighlight> | |||
Counts down even numbers from 10 to 0. | Counts down even numbers from 10 to 0. | ||
Latest revision as of 23:59, 14 March 2023
This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.
[for():] Roll Option
Executes a statement for a number of iterations based on a start and end value.
Usage
[for(var, start, end): body]
[for(var, start, end, stepsize): body]
[for(var, start, end, stepsize, separator): body]
Parameters
The var
variable counts from start
towards end
during the loop, and the optional stepsize
(default +1
) is added to var
at each iteration. Note that in the standard incrementing usage with a stepsize
of 1
, the body
does not execute when var
reaches end
.
Note that stepsize
must be integer and not 0. Floating values will be rounded down.
list_separator
default value is ","
. Some examples of other useful separators: nothing ""
, space " "
and break "<br>"
.
Examples
[for(i,0,10): "i is now " + i]
Counts up from 0 to 9.
[for(i,10,0,-2): "i is now " + i]
Counts down even numbers from 10 to 2.
[for(i,10,-1,-2): "i is now " + i]
Counts down even numbers from 10 to 0.
See Also
[foreach():], Introduction to Macro Loops
Version Changes
- 1.3b54 - Changed the comparison operator when comparing the
var
toend
when determining whether to continue executing a new iteration. In version 1.3b53 and earlier, on each iteration it compared ifvar
was less than or equal toend
. As of version 1.3b54, it is now comparing ifvar
is less thanend
.