json.rolls: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(4 intermediate revisions by 3 users not shown)
Line 5: Line 5:
|version=1.4.0.5
|version=1.4.0.5
|description=
|description=
Rolls the dice expression the requested number of times and returns a JSON Array with the result.
Rolls the dice expression the requested number of times and returns a JSON Array with the result.  This function takes 2 or 3 parameters and returns a json array or an array of arrays if the second dimension is provided.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
json.rolls(roll, dim1)
json.rolls(roll, dim1)
json.rolls(roll, dim1, dim2)
json.rolls(roll, dim1, dim2)
</source>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
{{param|roll|A string containing a dice roll expression.}}
{{param|roll|A string containing a dice roll expression. The dice expression must be in quotes as shown in the examples.}}
{{param|dim1|The dimension of the returned array.}}
{{param|dim1|The dimension of the returned array.}}
{{param|dim2|Optional: The second dimension for a two dimensional array.}}
{{param|dim2|Optional: The second dimension for a two dimensional array.}}


This function takes 2 or 3 parameters and returns a json array
''Example:''<syntaxhighlight lang="mtmacro" line>
json.rolls(roll, dim1, dim2) => returns a json array with the rolls performed
 
''Example:''<source lang="mtmacro" line>
{json.rolls("3d6", 6)} => [ 11, 7, 15, 8, 10, 13 ]
{json.rolls("3d6", 6)} => [ 11, 7, 15, 8, 10, 13 ]
</source>
</syntaxhighlight>


''Example:''
''Example:''
The three parameter version returns a two dimensional array
The three parameter version returns a two dimensional array
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
{json.rolls("3d6", 6, 4)} => [ [ 11, 13, 11, 13 ], [ 8, 11, 17, 10 ], [ 8, 11, 14, 11 ], [ 6, 8, 13, 6 ], [ 6, 11, 8, 10 ], [ 10, 7, 17, 11 ] ]
{json.rolls("3d6", 6, 4)} => [ [ 11, 13, 11, 13 ], [ 8, 11, 17, 10 ], [ 8, 11, 14, 11 ], [ 6, 8, 13, 6 ], [ 6, 11, 8, 10 ], [ 10, 7, 17, 11 ] ]
</source>
</syntaxhighlight>


|also=
|also=

Latest revision as of 23:59, 15 March 2023

json.rolls() Function

Introduced in version 1.4.0.5
Rolls the dice expression the requested number of times and returns a JSON Array with the result. This function takes 2 or 3 parameters and returns a json array or an array of arrays if the second dimension is provided.

Usage

json.rolls(roll, dim1)
json.rolls(roll, dim1, dim2)

Parameters

  • roll - A string containing a dice roll expression. The dice expression must be in quotes as shown in the examples.
  • dim1 - The dimension of the returned array.
  • dim2 - Optional: The second dimension for a two dimensional array.

Example:

{json.rolls("3d6", 6)} => [ 11, 7, 15, 8, 10, 13 ]

Example: The three parameter version returns a two dimensional array

{json.rolls("3d6", 6, 4)} => [ [ 11, 13, 11, 13 ], [ 8, 11, 17, 10 ], [ 8, 11, 14, 11 ], [ 6, 8, 13, 6 ], [ 6, 11, 8, 10 ], [ 10, 7, 17, 11 ] ]


See Also