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

escaping characters in outputted command buttons

1478732574
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
So, I'm trying to output a command button from a script so that users can click it to change some settings. The command syntax has a colon in it though, which breaks the command button since it is essentially a URL. I found  this thread from a few months ago where Silvyre suggested double escaping the offending character. This gets the command button output to the chat properly (it is clickable and brings up the roll query prompt it is supposed to), but the command doesn't work because now you have : right in the middle of the command where the colon was supposed to be. Escaping the colon only a single time results in the button no longer being clickable. Any ideas for a workaround (other than changing my command syntax)? Thanks, Scott
1478733074

Edited 1478733117
Silvyre
Forum Champion
I did some more digging on that. My findings : In order to use colons within API Command Buttons, they must be preceded by one of the following characters (URI delimiters): Forward slash (e.g. within /w gm) Question mark Hash (#)
1478733627
The Aaron
Pro
API Scripter
For similar cases in other scripts, I support more than one delimiter (for example you can use | and # interchangeably in TokenMod).
1478733654
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hrmm, ok. Thanks for the info Silvyre. Looks like I need to go redo my command syntax no matter what then.
1478733709
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The Aaron said: For similar cases in other scripts, I support more than one delimiter (for example you can use | and # interchangeably in TokenMod). Hmm, hadn't thought of that. I've already got | assigned to another delimiter, but I could set something else as the alternate delimiter to the colon.
1478755593
Lithl
Pro
Sheet Author
API Scripter
Scott C. said: I found&nbsp; this thread from a few months ago where Silvyre suggested double escaping the offending character. This gets the command button output to the chat properly (it is clickable and brings up the roll query prompt it is supposed to), but the command doesn't work because now you have &#58; right in the middle of the command where the colon was supposed to be. Escaping the colon only a single time results in the button no longer being clickable. Any ideas for a workaround (other than changing my command syntax)? Decode the incoming command, turning &amp;#58; back into a colon: // From <a href="http://stackoverflow.com/a/4339083/386178" rel="nofollow">http://stackoverflow.com/a/4339083/386178</a> String.prototype.decodeHTML = function() { var map = {"gt":"&gt;" /* , etc... */}; return this.replace(/&(#(?:x[0-9a-f]+|\d+)|[a-z]+);?/gi, function($0, $1) { if ($1[0] === "#") { return String.fromCharCode($1[1].toLowerCase() === "x" ? parseInt($1.substr(2), 16) : parseInt($1.substr(1), 10)); } else { return map.hasOwnProperty($1) ? map[$1] : $0; } }); }; At that point, just call something like msg.content.decodeHTML(). The normal API commands from chat will be unaffected, and the ones from an API command button with the HTML entity escaped colon will have the entity converted to the proper character.
1478756010
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I've got a command extract function; was just a matter of a couple keystrokes to add an alternate delimiter.
1478766395
Lithl
Pro
Sheet Author
API Scripter
Also worth noting:&nbsp; splitArgs can use any string or regex as a separator, and it's available from one-click install.