Difference between revisions of "Manual:DIL Manual/openroll()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
 
(checked against the compiler and the interpreter; example compiles)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= openroll() =
 +
'''Function''' (integer). Rolls an open-ended die: high rolls add another roll, low rolls subtract one.
  
 +
openroll(dice : integer, end : integer)
  
−
<span id="bforoll"></span>
+
Rolls a number from 1 to <code>dice</code>.
−
integer openroll( dice : integer , end : integer )
+
* If it is in the top <code>end</code> numbers (from <code>dice</code> - <code>end</code> + 1 up),
−
    dice : The size of the dice being rolled.
+
  it rolls again and adds, and goes on while the new roll is also in the top <code>end</code>.
−
    end : The margin for the open-ended roll.
+
* If it is below <code>end</code> (1 to <code>end</code> - 1), it rolls again and subtracts, and
−
    return: A random integer in approximately +/- 2^31 in worst case.
+
  goes on subtracting while that roll is in the top <code>end</code>.
−
    Example: i := openroll(100,5); The "100" roll continues on values
+
* Otherwise the result is the roll.
−
            96 - 100 and on values 1 - 5.
+
With <code>openroll(100, 5)</code>, 96 to 100 (5% of rolls) go on upwards and 1 to 4 (4%) go
 +
below 1. There is no upper or lower limit.
  
−
---~---~---~---~---~---~---~---~---
+
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| dice || integer || The size of the die.
 +
|-
 +
| end || integer || How many numbers at the top make the roll open-ended.
 +
|}
 +
 
 +
== Returns ==
 +
Integer: the roll. It is 0 unless <code>dice</code> and <code>end</code> are above 0 and
 +
<code>end</code> is smaller than <code>dice</code>/2 - 1 (so <code>openroll(20, 10)</code> is
 +
always 0).
 +
 
 +
== Notes ==
 +
* The game's own skill and spell checks use <code>openroll(100, 5)</code> (spells.zon,
 +
  function.zon).
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin integer contest(att : integer, defence : integer);
 +
code
 +
{
 +
  // above 0 is a success; usually between -50 and +50, now and then far more
 +
  return(openroll(100, 5) + att - defence - 50);
 +
}
 +
dilend
 +
</pre>
 +
A contest between an attack and a defence value, as the skill checks in function.zon work.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/rnd()|rnd()]]

Latest revision as of 23:04, 14 November 2026

openroll()

Function (integer). Rolls an open-ended die: high rolls add another roll, low rolls subtract one.

openroll(dice : integer, end : integer)

Rolls a number from 1 to dice.

  • If it is in the top end numbers (from dice - end + 1 up),
 it rolls again and adds, and goes on while the new roll is also in the top end.
  • If it is below end (1 to end - 1), it rolls again and subtracts, and
 goes on subtracting while that roll is in the top end.
  • Otherwise the result is the roll.

With openroll(100, 5), 96 to 100 (5% of rolls) go on upwards and 1 to 4 (4%) go below 1. There is no upper or lower limit.

Parameters

Name Type Meaning
dice integer The size of the die.
end integer How many numbers at the top make the roll open-ended.

Returns

Integer: the roll. It is 0 unless dice and end are above 0 and end is smaller than dice/2 - 1 (so openroll(20, 10) is always 0).

Notes

  • The game's own skill and spell checks use openroll(100, 5) (spells.zon,
 function.zon).

Example

dilbegin integer contest(att : integer, defence : integer);
code
{
   // above 0 is a success; usually between -50 and +50, now and then far more
   return(openroll(100, 5) + att - defence - 50);
}
dilend

A contest between an attack and a defence value, as the skill checks in function.zon work.

See also