FUDGE Die Demo

What is FUDGE Die Demo?

The only down side is a digital die(4) can't be used as emergency caltrops

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 fudge = RollPlayer.die(1, -1);
  3. 3: return { rollable : fudge };
  4. 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. 1: var demo = function() {

If we provide 2 arguments to die() the lower number is used as the bottom of the range and the higher number as the top of the range. The arguments can be provided in either order. Since the single argument version sets the top of the range and keeps the bottom fo the range at the default of 1, maybe it is more intuitive to provide the top of the range as the first argument. Or maybe it just feels right to put the lower number first. Either way will work.

  1. 2: var fudge = RollPlayer.die(1, -1);

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

  1. 3: return { rollable : fudge };
  2. 4: }();

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