Hello all!
I stuck Chapel’s <<event>>
macro in my game, and when using it in a specific way it only works on odd times you visit the passage (first time, third time, etc.). It doesn’t matter if you do anything, simply leaving and coming back will change it.
Here’s his minified Javascript which I’m using:
// events.min.js, for SugarCube 2, by Chapel
;Macro.add("trigger",{handler:function(){var t;return 2<this.args.length||0===this.args.length?this.error("incorrect number of arguments"):"string"!=typeof this.args[0]?this.error("first argument should be a string and a valid event type"):(t=this.args[0],void(1===this.args.length||this.args[1]&&"string"==typeof this.args[1]&&"document"===this.args[1].toLowerCase().trim()?$(document):$(this.args[1])).trigger(t))}}),Macro.add("event",{tags:["which"],handler:function(){var t,r,s=this.payload,e="",i="";return 2<this.args.length||0===this.args.length?this.error("incorrect number of arguments"):"string"!=typeof this.args[0]?this.error("first argument should be a string and a valid event type"):(2===this.args.length&&"string"==typeof this.args[1]&&(e=this.args[1]),t=this.args[0],void $(document).on(t,e,function(t){if(i=s[0].contents,1<s.length)for(r=1;r<s.length;r++)s[r].args.includes(t.which)&&(i+=s[r].contents);new Wikifier(null,i)}))}});
// end events.min.js
Here’s what I have in the testing passage:
<span id="a">$boot</span>\
[[test2]]
<span class="boot">replace</span>\
<<event "click" ".boot">>\
<<if ndef $boot or $boot is 1>>\
<<set $boot to 2>>\
<<replace "#a">>$boot<</replace>>\
<<else>>\
<<if $boot is 2>>\
<<set $boot to 1>>\
<<replace "#a">>$boot<</replace>>\
<</if>>\
<</if>>\
<</event>>\
(Incidentally, “boot” refers to the boot of a car you’re opening and closing. )
By “not working”, I mean that instead of changing 1 to 2, or 2 to 1, it’s replacing 1 with 1, or 2 with 2 (inspect shows that the span is in fact getting replaced, and if you leave and come back while $boot is still undefined it will replace it with 1 instead of 2 like it’s supposed to, and thus it continues replacing it with 1).
Now, if I use the <<link>>
macro it works perfectly:
<span id="a">$boot</span>\
[[test2]]
<<link "replace">>\
<<if ndef $boot or $boot is 1>>\
<<set $boot to 2>>\
<<replace "#a">>$boot<</replace>>\
<<else>>\
<<if $boot is 2>>\
<<set $boot to 1>>\
<<replace "#a">>$boot<</replace>>\
<</if>>\
<</if>>\
<</link>>\
However I don’t know how to make a <span>
into a <<link>>
macro, which is why I’m trying to get <<event>>
to work - and if I could use <<link>>
on a <span>
I would probably prefer <<event>>
because it’s as simple as adding a class, and usually works. Though if I knew how to use <<link>>
with a <span>
I could just use it as a workaround for this particular place that <<event>>
is having trouble with.
Thanks in advance superpeople!