http://eturnerx.blogspot.co.nz/2012/12/how-to-use-parameters-and-variables-in.html
It's not too hard, but there a few things to do to make things easier.
1) Some versions (older) of Jonah / Sugarcane don't run macros from until after the Start passage has been displayed. This means that if you use <<display>> in the Start passage (and even if that later nests into more <<display>> calls), then the macro will simply not run at all.
There are fixes about: ... [snip]
::Macros [script]
try {
version.extensions["customOperators"] = {
major: 1, minor: 0, revision: 0
};
macros["up"] = {
handler: function(place, macroName, params, parser) {
var attr = params[0];
var amt = 5;
if(params.length >= 2) amt = parseInt(params[1]);
if(isNaN(state.history[0].variables[attr])) state.history[0].variables[attr] = 0;
if(isNaN(state.history[0].variables["act" + attr])) state.history[0].variables["act" + attr] = 0;
state.history[0].variables[attr] += amt;
state.history[0].variables["act" + attr] += amt;
}
};
macros["down"] = {
handler: function(place, macroName, params, parser) {
var attr = params[0];
var amt = 5;
if(params.length >= 2) amt = parseInt(params[1]);
if(isNaN(state.history[0].variables[attr])) state.history[0].variables[attr] = 0;
if(isNaN(state.history[0].variables["act" + attr])) state.history[0].variables["act" + attr] = 0;
state.history[0].variables[attr] -= amt;
state.history[0].variables["act" + attr] += amt;
}
}
} catch (e) {
throwError(place,"macro setup failure: " + e.message);
}
!!Up
foo: <<print $foo>> (blank)
<<up "foo">>foo: <<print $foo>> (5)
actfoo: <<print $actfoo>> (5)
!!7Up
<<up "foo" 7>>foo: <<print $foo>> (12)
actfoo: <<print $actfoo>> (12)
!!Down
<<down "foo">>foo: <<print $foo>> (7)
actfoo: <<print $actfoo>> (17)
<<set $dieRoll = function(d){ return Math.floor(Math.random()*d)+1;}>>
You can have <<print $dieRoll(6)>> oranges and <<print $dieRoll(10)>> apples today!"You have <<print $oranges = $dieRoll(6);>> oranges.
That's right <<print $oranges>>.