roll: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 5: Line 5:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
roll(times, sides)
roll(times, sides)
</source>
</syntaxhighlight>
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
dice(times, sides)
dice(times, sides)
</source>
</syntaxhighlight>
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
d(times, sides)
d(times, sides)
</source>
</syntaxhighlight>
'''Parameters'''
'''Parameters'''
{{param|times|The number of times to roll the dice.}}
{{param|times|The number of times to roll the dice.}}
Line 27: Line 27:
'''Roll a twenty-sided dice'''
'''Roll a twenty-sided dice'''


 
<syntaxhighlight lang="mtmacro" line>
<source lang="mtmacro" line>
[t: roll(1, 20)]
[t: roll(1, 20)]
</source>
</syntaxhighlight>
Returns a number that is between {{code|1}} and {{code|20}}.
Returns a number that is between {{code|1}} and {{code|20}}.


'''Roll five ten-sided dice, using variables'''
'''Roll five ten-sided dice, using variables'''


 
<syntaxhighlight lang="mtmacro" line>
 
<source lang="mtmacro" line>
[h: DiceTimes = 5]
[h: DiceTimes = 5]
[h: DiceSides = 10]
[h: DiceSides = 10]
[t: roll(DiceTimes, DiceSides)]
[t: roll(DiceTimes, DiceSides)]
</source>
</syntaxhighlight>
Returns a number than is between {{code|5}} and {{code|50}}.
Returns a number than is between {{code|5}} and {{code|50}}.


'''Throw multiple dice'''
'''Throw multiple dice'''
Line 48: Line 47:
...and sort and sum the result. Note that roll() doesnt help with this. You have to roll individual dice and keep track yourself. Gladly MapTool does help with loops and listkeeping functions.  
...and sort and sum the result. Note that roll() doesnt help with this. You have to roll individual dice and keep track yourself. Gladly MapTool does help with loops and listkeeping functions.  


<source lang="mtmacro">
<syntaxhighlight lang="mtmacro">
[h: diceTimes = 5]
[h: diceTimes = 5]
[h: diceSides = 6]
[h: diceSides = 6]
Line 59: Line 58:
}]
}]
You rolled [r: listSort(listOfRolls, "N-")] = [r: sum].
You rolled [r: listSort(listOfRolls, "N-")] = [r: sum].
</source>
</syntaxhighlight>
Rolls 5 times a d6 and returns these as sorted list as well as the total.
Rolls 5 times a d6 and returns these as sorted list as well as the total.


  See also {{roll|count}}, {{func|listAppend}} and {{func|listSort}}.
: '''See also''' {{roll|count}}, {{func|listAppend}} and {{func|listSort}}.
&nbsp;


|also=
|also=

Latest revision as of 22:05, 14 March 2023

roll() Function

Generates random numbers to emulate dice rolls. You may also think of this function as a method of generating a random number between times and times*sides.

Usage

roll(times, sides)
dice(times, sides)
d(times, sides)

Parameters

  • times - The number of times to roll the dice.
  • sides - The number of sides the dice possess.

Note:

The roll function does not keep track of the individual dice rolled. In other words their results are lost, just the total is kept. How to roll dice when individual dice matter is shown in the examples.

Examples

Roll a twenty-sided dice
[t: roll(1, 20)]

Returns a number that is between 1 and 20.


Roll five ten-sided dice, using variables

[h: DiceTimes = 5]
[h: DiceSides = 10]
[t: roll(DiceTimes, DiceSides)]

Returns a number than is between 5 and 50.


Throw multiple dice

...and sort and sum the result. Note that roll() doesnt help with this. You have to roll individual dice and keep track yourself. Gladly MapTool does help with loops and listkeeping functions.

[h: diceTimes = 5]
[h: diceSides = 6]
[h: listOfRolls = ""]
[h: sum = 0]
[h, count(diceTimes), code: {
    [h: r = roll(1, diceSides)]
    [h: sum = sum+r]
    [h: listOfRolls = listAppend(listOfRolls, r)]
}]
You rolled [r: listSort(listOfRolls, "N-")] = [r: sum].

Rolls 5 times a d6 and returns these as sorted list as well as the total.

See also [count():], listAppend() and listSort().
 

See Also

For another method of rolling dice, see Dice Expressions.