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

Unable to run macro without a scene active #21

Closed Matthew-Whitlock closed 3 years ago

Matthew-Whitlock commented 3 years ago

Without Advanced Macros enabled, I can run the following macro without having to load any scenes (IE on just opening the program and before clicking to view anything):

game.tables.getName("Random Undara Encounters").draw();

However, with Advanced Macros enabled I get the error that we cannot run "get" on a null object, coming from this line:

context.token = args && typeof args[0] === "object" ? args[0].token : canvas.tokens?.get(context.speaker.token);

which leads to a call to foundry.js:19784:

get(objectId) {
    return this.documentCollection.get(objectId)?.object;
}

Which, finally, gives this error:

TypeError: Cannot read property 'get' of null
    at TokenLayer.get (foundry.js:19784)
    at Function.getTemplateContext (Macros.js:142)
    at MacroPF2e.renderMacro [as renderContent] (Macros.js:171)
    at MacroPF2e.executeMacro (Macros.js:204)
    at Hotbar._onClickMacro (foundry.js:28392)
    at HTMLLIElement.dispatch (jquery.min.js:2)
    at HTMLLIElement.v.handle (jquery.min.js:2)

It's not really high priority I'd assume, since I'll generally have a scene loaded, it just took time to work out the problem so I figured I'd post it here.