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

Roll queries with roll template in sendChat API?

1436191175

Edited 1436191342
DXWarlock
Sheet Author
API Scripter
I seem to be stuck trying to send a roll query in sendchat when using a template. If I do: sendChat('HealthColors', "/w GM " + "<br>Click buttons to toggle:" + "<br>Is on:[" + state.auraColorOn + "](!aura --On)" + "<br>Bar:[" + state.auraBar + "](!aura --bar ?{BarNumber?|1})"); It works fine, 2 buttons show up. But using this: sendChat('HealthColors', "/w GM &{template:default}" + "{{name=Click buttons to toggle:}}" + "{{Is on:=[" + state.auraColorOn + "](!aura --On)}}" + "{{Bar:=[" + state.auraBar + "](!aura --bar ?{BarNumber?|1})}}"); I get one (the first) button, but no second button. anyone have any clue whats going on? Does roll templates not accept query type inputs when using a button?
1436193975
The Aaron
Pro
API Scripter
Try subbing in some HTML entities for the { and } and such. I find that the parser can get confused at times and that helps: <a href="https://wiki.roll20.net/API:Chat#Entering_API_Butt" rel="nofollow">https://wiki.roll20.net/API:Chat#Entering_API_Butt</a>...
1436194096
DXWarlock
Sheet Author
API Scripter
That might work.Aaron to the rescue! Was going to steal your script div boxes with buttons, but its way too fancy and sorted out into various functions for me to tear apart and have anything useful left :)
1436194740

Edited 1436194772
DXWarlock
Sheet Author
API Scripter
Hmm nope sendChat('HealthColors', "/direct GM &{template:default}" + "{{name=Health Colors-Click buttons to toggle:}}" + "{{Is on:=&lt;a href=!aura --On&gt;"+state.auraColorOn+"&lt;/a&gt;}}" + "{{Bar:=&lt;a href=!aura --bar ?{BarNumber?|1}&gt;"+state.auraBar+"&lt;/a&gt;}}" + "{{Use Tint:=&lt;a href=!aura --tint&gt;"+state.auraTint+"&lt;/a&gt;}}" + "{{Percent:=&lt;a href=!aura --perc ?{Percent?|90}&gt;"+state.auraPerc+"&lt;/a&gt;}}" + "{{Dead:=&lt;a href=!aura --dead&gt;"+state.auraDead+"&lt;/a&gt;}}"); Gives me only the 3 that dont have a query popup :\ The 2 with them dont show up at all.
1436195224

Edited 1436195262
Lithl
Pro
Sheet Author
API Scripter
Does it work with /direct without using a roll template? (After all, the roll template is just prettying up the output, which you can do manually with /direct)
1436195438

Edited 1436195590
DXWarlock
Sheet Author
API Scripter
Just tried that, doesn't seem to work correctly. Still no popup for the question. You can click it and it does the command, but doesnt ask you, and returns nothing as an answer. this is what I have: sendChat('HealthColors', "/direct "+ "&lt;a href=!aura on&gt;"+state.auraColorOn+"&lt;/a&gt;" + "&lt;a href=!aura bar ?{BarNumber?|1}&gt;"+state.auraBar+"&lt;/a&gt;" + "&lt;a href=!aura tint&gt;"+state.auraTint+"&lt;/a&gt;" + "&lt;a href=!aura perc ?{Percent?|90}&gt;"+state.auraPerc+"&lt;/a&gt;" + "&lt;a href=!aura dead&gt;"+state.auraDead+"&lt;/a&gt;");
1436196026

Edited 1436196101
DXWarlock
Sheet Author
API Scripter
Ok I got it working without the template and direct..I needed both quote types to declare it correctly: '&lt;a href="!aura bar ?{BarNumber?|1}"&gt;'+state.auraBar+'&lt;/a&gt;' But just adding the template info like: '{{Bar:=&lt;a href="!aura bar ?{BarNumber?|1}"&gt;'+state.auraBar+'&lt;/a&gt;}}' Breaks it. Guess ill have to work out making my own div info to put it in :|
1436196300
The Aaron
Pro
API Scripter
BTW, when you put HTML Entities into the chat, you have to put them in like this for them to show up: &amp;amp;#63;
1436196569

Edited 1436196845
DXWarlock
Sheet Author
API Scripter
I dont think its that though, but I could be wrong. All the ones that are normal !aura on, !aura tint ,ect format and show up fine doing it either way, its just the ones with a query that dont add a row. Testing it in chat, I think its that the query wants to ask you the question before it makes the button. like typing [Attack Roll](?{Test|answer}) into chat directly doesnt ask you when you push it, it asks you when you hit enter. So in the API it has 'no one' to ask and cancels the command, sort of like closing the popup. So need to figure out a way to ask a question with a button since now I dont think its the API or the template doing it, its the question popup.
Roll queries don't work with the API at all.
1436197528

Edited 1436197680
The Aaron
Pro
API Scripter
HoneyBadger said: Roll queries don't work with the API at all. The way he's wanting to use them, they should. I do it all the time (see Group Initiative's prompts for number of dice, sides of die, etc..). The key is that you have to replace the characters that trigger the expansion of the Roll Query (or any macro, really) enough times that they aren't expanded until the button is pressed. In my more recent scripts I use this function: var esRE = function (s) { var escapeForRegexp = /(\\|\/|\[|\]|\(|\)|\{|\}|\?|\+|\*|\||\.|\^|\$)/g; return s.replace(escapeForRegexp,"\\$1"); }, HE = (function(){ var entities={ '&lt;' : '&'+'lt'+';', '&gt;' : '&'+'gt'+';', "'" : '&'+'#39'+';', '@' : '&'+'#64'+';', '{' : '&'+'#123'+';', '|' : '&'+'#124'+';', '}' : '&'+'#125'+';', '[' : '&'+'#91'+';', ']' : '&'+'#93'+';', '"' : '&'+'quot'+';' }, re=new RegExp('('+_.map(_.keys(entities),esRE).join('|')+')','g'); return function(s){ return s.replace(re, function(c){ return entities[c] || c; }); }; }()); It will perform the escapes necessary to allow the expression to be passed on. The more evaluations the expression needs to pass through, the more escaping you need to do. (Passing things into tipsy titles takes two calls: HE(HE(&lt;something)) ). You might try injecting some calls to that in your code and see if it fixes things? '{{Bar:=&lt;a href="'+ HE( !aura bar ?{BarNumber?|1} ) +'"&gt;'+state.auraBar+'&lt;/a&gt;}}' '{{Bar:=&lt;a href="'+ HE(HE( !aura bar ?{BarNumber?|1} )) +'"&gt;'+state.auraBar+'&lt;/a&gt;}}' '{{Bar:=&lt;a href="'+ HE(HE(HE( !aura bar ?{BarNumber?|1} ))) +'"&gt;'+state.auraBar+'&lt;/a&gt;}}'
1436197574
DXWarlock
Sheet Author
API Scripter
They work ok if I do it this way: sendChat('HealthColors', "/w GM &lt;b&gt;&lt;br&gt;"+ 'Is On: &lt;a href="!aura on"&gt;'+state.auraColorOn+'&lt;/a&gt;&lt;br&gt;' + 'Bar: &lt;a href="!aura bar ?{BarNumber?|1}"&gt;'+state.auraBar+'&lt;/a&gt;&lt;br&gt;' + 'Use Tint: &lt;a href="!aura tint"&gt;'+state.auraTint+'&lt;/a&gt;&lt;br&gt;' + 'Percentage: &lt;a href="!aura perc ?{Percent?|90}"&gt;'+state.auraPerc+'&lt;/a&gt;&lt;br&gt;' + 'Show Dead: &lt;a href="!aura dead"&gt;'+state.auraDead+'&lt;/a&gt;'); Just ugly as all get out...