roll.count: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Macros:Special Variables:roll.count moved to roll.count: Moved to main namespace.)
No edit summary
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The special variable ''roll.count'' holds the current iteration of the [[ Macros:Branching_and_Looping#COUNT_Option | [COUNT(): ] ]] roll option. ''roll.count'' begins at 0.  
The special variable ''roll.count'' holds the current iteration of current loop. It may be used with the following roll options for looping:
 
* [[ Macros:Branching_and_Looping#COUNT_Option | COUNT(): ]]
* [[ Macros:Branching_and_Looping#FOR_Option | FOR(): ]]
* [[ Macros:Branching_and_Looping#FOREACH_Option | FOREACH(): ]]
* [[ Macros:Branching_and_Looping#WHILE_Option | WHILE(): ]]
 
The ''roll.count'' begins at 0.  


==Examples==
==Examples==
 
'''Simple Count'''
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[COUNT(5, "<br>"): "This is roll " + roll.count]
[COUNT(5, "<br>"): "This is roll " + roll.count]
</source>
</syntaxhighlight>


Outputs:
''Outputs:''


  This is roll 0
  This is roll 0
Line 14: Line 21:
  This is roll 3
  This is roll 3
  This is roll 4
  This is roll 4
'''Inner and Outer Loop'''
<syntaxhighlight lang="mtmacro" line>
[r,foreach(item,"a,b,c,d,e,f",""),code: {
Loop: [r: roll.count] - [r: item] -
[r,count(6): roll.count]<br>
}]
</syntaxhighlight>
''Outputs:''
  Loop: 0 - a - 0, 1, 2, 3, 4, 5
  Loop: 1 - b - 0, 1, 2, 3, 4, 5
  Loop: 2 - c - 0, 1, 2, 3, 4, 5
  Loop: 3 - d - 0, 1, 2, 3, 4, 5
  Loop: 4 - e - 0, 1, 2, 3, 4, 5
  Loop: 5 - f - 0, 1, 2, 3, 4, 5


==Related Pages==
==Related Pages==


* [[Macros:Variables:list_of_special_variables|List of Special Variables]]
* [[Macros:Branching_and_Looping | Branching and Looping Options ]]
* [[Macros:Branching_and_Looping | Branching and Looping Options ]]
[[Category:Special Variable]]
[[Category:Macro Function]]

Latest revision as of 23:59, 4 July 2023

The special variable roll.count holds the current iteration of current loop. It may be used with the following roll options for looping:

The roll.count begins at 0.

Examples

Simple Count

[COUNT(5, "<br>"): "This is roll " + roll.count]

Outputs:

This is roll 0
This is roll 1
This is roll 2
This is roll 3
This is roll 4

Inner and Outer Loop

[r,foreach(item,"a,b,c,d,e,f",""),code: {
	Loop: [r: roll.count] - [r: item] - 
	[r,count(6): roll.count]<br>
}]

Outputs:

 Loop: 0 - a - 0, 1, 2, 3, 4, 5 
 Loop: 1 - b - 0, 1, 2, 3, 4, 5 
 Loop: 2 - c - 0, 1, 2, 3, 4, 5 
 Loop: 3 - d - 0, 1, 2, 3, 4, 5 
 Loop: 4 - e - 0, 1, 2, 3, 4, 5 
 Loop: 5 - f - 0, 1, 2, 3, 4, 5

Related Pages