Thank you, it did answer my question and help me get my code working. But I also run into problems with using it together with for loop. For example, the following code works. It very bare-bone and I am setting payload for createShadowWrapper manually by hand.
Macro.add('event', {
isAsync : true,
tags: ['condition', 'effect'],
handler: function () {
const $link = $(document.createElement('button'));
let passage;
for (var i = 0; i < this.payload.length; i++) {
if (this.payload[i].name === 'event') {
$link.append(document.createTextNode(this.payload[i].args[0].text));
passage = this.payload[i].args[0].link;
}
if (this.payload[i].name === 'condition') {
if (!!Scripting.evalJavaScript(this.payload[i].args.full)) {
}
else {
$link.addClass('inactive')
}
}
if (this.payload[i].name === 'effect') {
}
}
$link.ariaClick(
this.createShadowWrapper(
() => Wikifier.wikifyEval(this.payload[2].contents.trim()),
() => Engine.play(passage)
))
$link
.addClass('macro-button')
.appendTo(this.output);
}
});
But if I move the $link.ariaClick() inside for loop it doesn't work anymore.
Macro.add('event', {
isAsync : true,
tags: ['condition', 'effect'],
handler: function () {
const $link = $(document.createElement('button'));
let passage;
for (var i = 0; i < this.payload.length; i++) {
if (this.payload[i].name === 'event') {
$link.append(document.createTextNode(this.payload[i].args[0].text));
passage = this.payload[i].args[0].link;
}
if (this.payload[i].name === 'condition') {
if (!!Scripting.evalJavaScript(this.payload[i].args.full)) {
}
else {
$link.addClass('inactive')
}
}
if (this.payload[i].name === 'effect') {
$link.ariaClick(
this.createShadowWrapper(
() => Wikifier.wikifyEval(this.payload[i].contents.trim()),
() => Engine.play(passage)
))
}
}
$link
.addClass('macro-button')
.appendTo(this.output);
}
});
What could be the reason? Is something wrong with my code.