mclemente / fvtt-advanced-macros

Use handlebars templating, recursive macro calls and call macros with arguments or directly from chat.
MIT License
15 stars 9 forks source link

InternalError: too much recursion #55

Closed MazerD closed 1 year ago

MazerD commented 1 year ago

I'm getting the following error when a player tries to use a macro I've set up to run as GM (it works as expected if I run it myself as the actual GM):

InternalError: too much recursion
      dt https://<mywebsite>/foundry/scripts/socket.io.min.js:6
      yt https://<mywebsite>/foundry/scripts/socket.io.min.js:6
      (above and below message is repeated 127 times)
      yt https://<mywebsite>/foundry/scripts/socket.io.min.js:6
Macros.js:204:13
      executeMacro https://<mywebsite>/foundry/modules/advanced-macros/Macros.js:204

The macros in question are below, for context this is on Foundry 9.280 and Advanced Macros 1.15 (I'm stuck on v9 Foundry until the Lancer system updates). I didn't write the macros myself so I'm a little unsure if there's just a problem in how they're written, I couldn't find a reference anywhere for the syntax? I realize the syntax is a Foundry thing not you guys, just apologies in advance if it's on my end.

This one is not set to run as GM:

// Apply Conditions

let targets = Array.from(game.user.targets);
if (targets.length === 0) return ui.notifications.info("Please target at least one actor!");

let options = [];

game.cub.conditions.forEach((item) => {
    targets.forEach((target) => {
        if (!game.cub.hasCondition(item.name, target)) options.push(item.name);
    });
});

if (options.length === 0) return ui.notifications.info("There are no valid conditions to apply!");
game.macros.getName("Condition-Toggler").execute(targets, [... new Set(options)], "Apply");

The above macro calls this one (named Condition-Toggler) which is set to run as GM:

// Set Conditions

const [targets, options, labelText] = args;
let optionText = '';

options.sort();
options.forEach((item) => {    optionText += `<option value="${item}">\n`; });

let content = `
<form>
    <div class="form-group">
        <label for="condition">Condition:</label>
        <input list="conditions" id="condition" name="condition"/ autofocus>
        <datalist id="conditions">
            ${optionText}
        </datalist>
    </div>
</form>
`

new Dialog({
    title: `Select Condition`,
    content: content,
    buttons: {
        yes: {
            icon: "<i class='fas fa-check'></i>",
            label: labelText,
            callback: (html) => {
                let condition = html.find('#condition').val();
                if (!game.cub.conditions.some(el => el.name === condition)) {
                    return ui.notifications.info("Select a valid condition.");
                }
                targets.forEach((target) => {
                    let hasCondition = game.cub.hasCondition(condition, target);
                    if (labelText === "Apply" && !hasCondition) {
                        game.cub.addCondition(condition, target);
                    } else if (labelText === "Remove" && hasCondition) {
                        game.cub.removeCondition(condition, target);
                    }
                });
            }
        },
        no: {
            icon: "<i class='fas fa-times'></i>",
            label: `Cancel`
        },
    },
    default: "yes"
}).render(true);
mclemente commented 1 year ago

I'm sorry to say this version is too old for me to look up for a fix. Advanced Macros has pretty much been rewritten since Foundry V9, to the point this might've been fixed already or might break up for another reason entirely, and Foundry V11 is already on the horizon. I'd wait on your system updating to V10 and come back with this issue.

mclemente commented 1 year ago

OP never came back and Foundry V11 is probably being released tomorrow, where it'll break macros that assume args is an Array, like this one.