Revision of Twine bugfix: "and" and "or" in strings in <<set>>, <<print>> and <<if>> from Wed, 04/24/2013 - 11:07

As you know from reading my macro reference, code parameters passed to <<if>>, <<set>>, <<print>> and <<remember>> have their operators ("and", "or", "$", "not", etc.) converted to Javascript equivalents ("&&", "||", etc.) when they're executed.

But, due to a bug, this conversion is also applied to "operators" that are inside strings passed to these macros. So, <<print "Vast and large">> will print "Vast && large", and <<print "You find $10">> will print "You find state.history[0].variables.10".

Now, I've sent out a pullreq to the Twine GitHub repo that fixes this, but in the meantime, if you're stymied by this bug, you can fix it with this script:

Wikifier.parse = function (b) {
    function alter(from,to) {
        var g = "(?=(?:[^\"'\\\\]*(?:\\\\.|['\"](?:[^\"'\\\\]*\\\\.)*[^\"'\\\\]*['\"]))*[^'\"]*$)";
        return b.replace(new RegExp(from+g,"gi"),to);
    }
    b = alter("\\$","state.history[0].variables.");
    b = alter("\\beq\\b", " == ");
    b = alter("\\bneq\\b", " != ");
    b = alter("\\bgt\\b", " > ");
    b = alter("\\beq\\b", " == ");
    b = alter("\\bneq\\b", " != ");
    b = alter("\\bgt\\b", " > ");
    b = alter("\\bgte\\b", " >= ");
    b = alter("\\blt\\b", " < ");
    b = alter("\\blte\\b", " <= ");
    b = alter("\\band\\b", " && ");
    b = alter("\\bor\\b", " || ");
    b = alter("\\bnot\\b", " ! ");
    return b
};

Again, note that in some versions this will be loaded after the Start passage has rendered.