successPool Demo

What is successPool Demo?

A successPool returns the number of result from within the pool that meet or exceed a specified target number.

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. 1: var demo = function() {
  2. 2: var d10 = RollPlayer.die(10);
  3. 3: var target_number = 6;
  4. 4: var perception = 4;
  5. 5: var investigation = 3;
  6. 6: var classic_WoD = RollPlayer.successPool(d10, d10, d10, d10, d10, d10, d10);
  7. 7: classic_WoD.set_target(target_number);
  8. 8: return { rollable : classic_WoD };
  9. 9: }();

Explanations

We're creating a wrapper object called demo so that the template code can access the inner workings of this particular example.

  1. 1: var demo = function() {

We can build a classic World of Darkness style roll using a successPool() of d10s and a target number of 6.

  1. 2: var d10 = RollPlayer.die(10);
  2. 3: var target_number = 6;

We can use any method we want to build our successPool(), we just need to know how many d10s to place into it. Provided a list of character traits we could do it programatically. But I'll leave that as an exercise for the reader.

  1. 4: var perception = 4;
  2. 5: var investigation = 3;

The successPool() will roll all the dice used to create it, compare them to the target number, and return the count of results that met or exeeded the target.

We can chain the call to set_target() or split it across 2 lines.

  1. 6: var classic_WoD = RollPlayer.successPool(d10, d10, d10, d10, d10, d10, d10);
  2. 7: classic_WoD.set_target(target_number);

Return an object so that our template code can access the star of this example as demo.rollable

  1. 8: return { rollable : classic_WoD };
  2. 9: }();

Tutorial Builder is © Christian Heilmann, 2008. Licensed under the BSD license.