> The usual way is for roll to set an attribute (say last_roll: INTEGER)
> to the value produced. Then you call `roll' and follow by accessing the
> value of `last_roll'.
I did something similar to that. I created roll(count, side, offset :
Integer)
and created routines to get the data of the last roll (result, count,
side and offset).
>
> Note that I wouldn't make `side' an argument of `roll'. rather I would
> make it an attribute of the class. You set it in the creation
> procedure, and have a different object for a 6-sided die, and a
> 20-sided die.
What's the benefit of that?
>
> Although I wouldn't really want to transfer the 3d6, 1d100 examples
> directly from an rpg to my program. Instead I would go for the
> abstract of a random number distribution, and sample that directly
> (you might name the distribution objects with names such as 3d6
> though, within an rpg).
That would be too much work since I want the GM/Player to be able to
roll any dice-combination needed for the rpg played with the help of
this tool. This incudes parsing Strings of the type 3d6+12 to create
the proper output. Transfering that in the tool into the correct
distribution is far complexer to programm as parsing the string,
rolling the die-object 3 times, interpreting the result as 6 sided die
and adding all together including the 12.


|