What is sumPool Demo?
A sumPool rolls multiple dice (or other rollables) and returns the sum of the individual rolls as a result.
Example
Result:
How the Template Works
The code for this demo creates an object showcasing a feature of the RollPlayer.js
library and returns it to the template as demo.rollable
. Both when the page
loads and when the button above is pressed the template code calls demo.rollable.roll()
and the returned result is displayed above. This process is identicle for all the demos
allowing the explanations below to focus on only the object being demoed.
Every result is also logged to the console
if you want to see a history after
a bunch of button clicks.
Version
1.0
Authors
- Derek Pennycuff
Full source
- 1: var demo = function() {
- 2: var pool_3d6 = RollPlayer.sumPool(RollPlayer.die(), RollPlayer.die(), RollPlayer.die());
- 3: return { rollable : pool_3d6 };
- 4: }();
Explanations
We're creating a wrapper object called demo
so that the template code can access the inner workings of this particular example.
- 1: var demo = function() {
We can call the functions to produce the dice inside the call to sumPool() or we could store them in variables to be fed into sumPool() later. We can use as many dice as we want. But for this demo we'll do 3d6. Remember that die() defaults to a d6 if no arguments are supplied.
Roll 6 times, in order. You get what you get. No whining.
- 2: var pool_3d6 = RollPlayer.sumPool(RollPlayer.die(), RollPlayer.die(), RollPlayer.die());
Return an object so that our template code can access the star of this example as demo.rollable
- 3: return { rollable : pool_3d6 };
- 4: }();