Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Calling a Macro from the API

1539984912

Edited 1539989988
Hey guys, I'm trying to have a macro to be executed in a certain condition. I already have text being correctly printed in such condition, by following some of the answers in the forums. var who = getObj('character', token.get('represents')); if (!who) { who = selectedToken.get('name'); } else { who = 'character|' + who.id; } sendChat(who,'%{' + token.get('represents') + '|shaped_statblock\}'); The current output is something like Character Name: -Character_Code|shaped_statblock Is there a way to for the macro to be executed? Addendum: shaped_statblock is a default macro from the Shaped D&D5e Character Sheet.
1540154893
The Aaron
Pro
API Scripter
There are some caveats to do thing this.&nbsp; Take a look at this thread:&nbsp; <a href="https://app.roll20.net/forum/post/6608405/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/6608405/slug%7D</a> There's also a script I wrote that executes macros.
1540198286
GiGs
Pro
Sheet Author
API Scripter
To explain a bit more, you cant simply use sendchat and sent Ability/Macro text to the window. It wont run. The way to do it is to access the campaign's Abilities object, and grab the full text of the Ability, and print that to chat (with a valid character/id as the sender).
1540203776
The Aaron
Pro
API Scripter
Just to clairity, there isn’t a way to set who the sender is from the API. You can change what is displayed as the speaker, but anything the macro/ability does will be done as the API. API commands that are a part of the macro/ability will need to handle that case if it’s important to them.&nbsp; Additionally, anything that would prompt the user ( @{target}, ?{query} ) won’t work and will need to be removed, avoided, or parsed by the API. @{selected} references will fail and must be changed. @{attribute} references that assume the current character (in character abilities) must be made explicit by the API or in the ability.&nbsp;