Twiddle: Twee Macros
Restart Story
Save
Sign up
// Requires sprintf, jQuery, underscore, Grass.Macro, Grass.Macros Macros.addMacros({ 'CyclingLink' : { "version": {major:1, minor:0, revision:0}, "requiresId": true, "parameters" : [new Macro.Parameter('saveTo', 'Variable to save to', 'variablename'), new Macro.Parameter('possibleValues', 'Variable to save to', 'string', {"length": "rest"})], "traverseAsInGameHTML": function(parser, wrappedContext, renderingEnvironment, source, parameters, contents, attributes) { return sprintf('
%s
', attributes.id, wrappedContext.load(parameters.saveTo) || parameters.possibleValues[0]); }, "traverseAsInGameBehavior": function(parser, source, parameters, contents, attributes, additionalParameters) { var index = 0; var postRenderContext = additionalParameters.postRenderContext; if (postRenderContext.load(parameters.saveTo)) { index = _.indexOf(parameters.possibleValues, postRenderContext.load(parameters.saveTo)); } postRenderContext.save(parameters.saveTo, parameters.possibleValues[index]); additionalParameters.jqControl.click(function cycle() { index = ++index % parameters.possibleValues.length; $(this).text(parameters.possibleValues[index]); postRenderContext.save(parameters.saveTo, parameters.possibleValues[index]); }); return source; } } }); //cyclinglink
Twine
Render