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

API command buttons w/ selected and target macros

1477677123

Edited 1477677663
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Whenever I try to create a chat command button in the chat through the API, it seems to always strip out the macros @{selected|attr} and @{target|macro} For example, if I do sendChat('who', '[Do the Thing](!doTheThing @{selected|token_id} @{target|token_id})'); it doesn't process selected or target at all. This only happens if the command is sent via sendChat() or through API command buttons rendered with sendChat(). If I enter in !doTheThing @{selected|token_id} @{target|token_id} manually through the chat, it works fine. Inside the API console, I also get the following error: "ERROR: Unable to find character selected in chat command." "ERROR: Unable to find character target in chat command."
1477745436
Silvyre
Forum Champion
Not sure if this helps, but you could escape the @ signs such that the Attributes are only called when the button is clicked, and not when the button is sent to the chat.
1477753456

Edited 1477753885
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I think it is due to the fact that api command buttons resolve their attribute calls when they are outputted, not when they are clicked (at least this is how it works for roll queries) EDIT: What happens if you do a formatted button (a la using the makeButton function from Aaron's scripts)? I know I've used those with roll queries before, might work for these as well. makeButton = function(command, label, backgroundColor, color){         return templates.button({             command: command,             label: label,             templates: templates,             defaults: defaults,             css: {                 color: color,                 'background-color': backgroundColor             }         });     },
1477941100

Edited 1477941168
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Silvyre said: Not sure if this helps, but you could escape the @ signs such that the Attributes are only called when the button is clicked, and not when the button is sent to the chat. Escaping it by \@, \\@, or encodeURIComponent('@') hasn't worked. Scott C. said: I think it is due to the fact that api command buttons resolve their attribute calls when they are outputted, not when they are clicked (at least this is how it works for roll queries) EDIT: What happens if you do a formatted button (a la using the makeButton function from Aaron's scripts)? I know I've used those with roll queries before, might work for these as well. makeButton = function(command, label, backgroundColor, color){         return templates.button({             command: command,             label: label,             templates: templates,             defaults: defaults,             css: {                 color: color,                 'background-color': backgroundColor             }         });     }, Could you provide a link to wherever his library is in the Roll20 API repo? Roll queries work fine, but I might try this for selected and target as well.
1477943337

Edited 1477943464
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Don't know about his library, I just took that from one of my scripts (either  EasyExperience or  PageNavigator ) which was originally taken from one of his scripts (can't remember which one at the moment).
1477944140
Silvyre
Forum Champion
Stephen L. said: Silvyre said: Not sure if this helps, but you could escape the @ signs such that the Attributes are only called when the button is clicked, and not when the button is sent to the chat. Escaping it by \@, \\@, or encodeURIComponent('@') hasn't worked. Try escaping it using the HTML entities, i.e. @ or @
1477944478

Edited 1477944522
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Silvyre said: Stephen L. said: Silvyre said: Not sure if this helps, but you could escape the @ signs such that the Attributes are only called when the button is clicked, and not when the button is sent to the chat. Escaping it by \@, \\@, or encodeURIComponent('@') hasn't worked. Try escaping it using the HTML entities, i.e. @ or @ Escaping it with & #64; did the trick! Thanks!