rerollOnce

From RPTools Wiki
Revision as of 22:11, 14 March 2023 by Taustin (talk | contribs)
Jump to navigation Jump to search

rerollOnce() Function

Introduced in version 1.7
Generates random numbers to emulate dice rolls; returns a dice roll similar to roll() with the difference being that each die rolled that is lower than the minimum parameter is rerolled and replaced by the new value. An option can allow the higher of the two values to be chosen instead. Differs from reroll() in that new values lower than minimum are allowed, and are not rerolled indefinitely.

Usage

rerollOnce(times, sides, minimum)
rerollOnce(times, sides, minimum, chooseHigher)

Parameters

  • times - The number of times to roll the dice.
  • sides - The number of sides the dice possess.
  • minimum - The lowest number a dice rolled can return without being rerolled.
  • chooseHigher - Whether the original die may be preserved if it was higher than the rerolled value. Defaults to false.

Examples

Roll two six-sided dice, rerolling any dice rolled lower than 3 (and keeping the new values):
[t: rerollOnce(2, 6, 3)]

Roll two six-sided dice, rerolling any dice rolled lower than 3, and choose the higher of the two values:

[t: rerollOnce(2, 6, 3, 1)]

Note that if multiple dice are rolled (times > 1), each die is rolled in sequence, and immediately rerolled if necessary. For example:

[t: rerollOnce(2, 6, 3)]
[getNewRolls()]
May return 5 [2, 1, 2, 4] - the first die produced a 2, which was rerolled and replaced by a 1. The second die also produced a 2, and was rerolled and replaced by a 4. The total returned is then 5. If chooseHigher was set to true, the first 2 would not have been replaced by a lower value, so the total returned would instead have been 6 for the same sequence of rolls.

See Also

For another method of rolling dice, see Dice Expressions.