Cuttlepress

Blogging about Hacker School?

Day 15

Today’s Sass with Moshe was implementing some beautiful swanky buttons. In Javascript, I decided to take a break from unmitigated JS/Canvas to try my hand at writing a Twine macro. After doing a bunch of reading and examining existing code (from the Porpentine’s resource list), I made this slightly silly attempt at a macro that poorly imitates a built-in Twine markup feature: making an external link.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
try {
  version.extensions['exlink'] = {
    major:1, minor:0, revision:0
  };
  macros['exlink'] = {
    handler: function(place, macroName, params, parser) {
      l = Wikifier.createExternalLink(place, "http://"+params[0]);
      insertElement(l,"span",null,null,params[1]||params[0]);
      // http://www.gimcrackd.com/etc/api/files/functions-js.html#insertElement
    },
    init: function() { },
  };
} catch(e) {
  throwError(place,"exlink Setup Error: "+e.message);
}

Obviously not useful on its own, but enough to convince me I’ve started to get the hang of the thing.