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 template inside roll query?

1629489145

Edited 1629489201
Grinning Gecko
Pro
Sheet Author
I have a roll button: <button type="roll" value="?{Add damage modifier?| None,Damage: [[@{damage}]]| Punch,Damage: [[@{damage}+@{mod_punch}]]| P.S. Bonus,Damage: [[@{damage}+@{mod_ps_bonus}]] }" name="roll_bonus_damage" ></button> Instead of, for example: Damage: [[@{damage}]] I'd like to use a roll template, like: &{template:custom} {{title=@{character_name} inflicts damage!}} {{Damage=[[@{damage}]]}} However I can't figure out the correct syntax. Replacing the former string with the latter causes some weird parsing and doesn't work properly: <button type="roll" value="?{Add damage modifier?| None,&{template:custom} {{title=@{character_name} inflicts damage!}} {{Damage=[[@{damage}]]}} | Punch,Damage: [[@{damage}+@{mod_punch}]]| P.S. Bonus,Damage: [[@{damage}+@{mod_ps_bonus}]] }" name="roll_bonus_damage" ></button> What's the correct way to do this?
1629490295
GiGs
Pro
Sheet Author
API Scripter
You're probably trying to put too much in the query. You just need something like value="&{template:custom} {{title=@{character_name} inflicts damage!}} {{Damage=?{Add damage modifier?| None,[[@{damage}]]| Punch,[[@{damage}+@{mod_punch}]]| P.S. Bonus,[[@{damage}+@{mod_ps_bonus}]]}" It's trickier if you want to report whether it's a punch or whatever in the output, but for the code above this should do. You could also do the end part {{Damage=[[@{damage} + ?{Add damage modifier?| None,0| Punch,@{mod_punch}| P.S. Bonus,@{mod_ps_bonus} } ]] It just depends on how you prefer to arrange it.
Thanks! Nice to see both methods. Gives me a better understanding of the syntax.
As a follow-up to this, is it possible to define the roll template based on the response to the query? So that if you choose answer A it uses template A, but if you choose answer B it uses template B? Any time I try to reference a template in an answer part of the query it breaks the syntax.
1630605965
GiGs
Pro
Sheet Author
API Scripter
You cant change the template that's used, but you can essentially build two layouts of a template and choose which to show based on a value. Just use the logic helper.
Thanks. That's what I suspected.
1630953604

Edited 1630953664
Grinning Gecko
Pro
Sheet Author
GiGs said: It's trickier if you want to report whether it's a punch or whatever in the output, but for the code above this should do. It seems that I'm now in a situation where I need to do this. I've looked at&nbsp; <a href="https://app.roll20.net/forum/post/5861626/how-do-you-do-a-roll-query-macro-that-gives-a-template-answer" rel="nofollow">https://app.roll20.net/forum/post/5861626/how-do-you-do-a-roll-query-macro-that-gives-a-template-answer</a> &nbsp;and&nbsp; <a href="https://app.roll20.net/forum/post/3205105/roll-queries-and-macro-templates" rel="nofollow">https://app.roll20.net/forum/post/3205105/roll-queries-and-macro-templates</a> &nbsp;and&nbsp; <a href="https://wiki.roll20.net/Macros#Advanced_Usage_for_Roll_Queries" rel="nofollow">https://wiki.roll20.net/Macros#Advanced_Usage_for_Roll_Queries</a>, &nbsp;but no matter what I do it doesn't parse correctly. Really basic examples that I've tried: value="&amp;{template:custom} ?{Type of Attack| Magic,{{title=magic}}| Psionic,{{title=psionic}} }" value="&amp;{template:custom} ?{Type of Attack| Magic,{{title=magic&amp;#125;&amp;#125;| Psionic,{{title=psionic&amp;#125;&amp;#125; }" In the query prompt, these show: Magic,{{title=magic value="?{Type of Attack| Magic,&amp;{template:custom} {{title=magic}}| Psionic,&amp;{template:custom} {{title=psionic}} }" value="?{Type of Attack| Magic,&amp;{template:custom&amp;#125; {{title=magic&amp;#125;&amp;#125;| Psionic,&amp;{template:custom&amp;#125; {{title=psionic&amp;#125;&amp;#125; }" In the query prompt, these show Magic,&amp;{template:custom What am I doing wrong?
1630957255
GiGs
Pro
Sheet Author
API Scripter
I dont use queries much, especially not in character sheets, but IIRC there might currently be a bug in the way html entities are passed, and you might need to put an extra level of nesting, like so: value="?{Type of Attack| Magic,&amp;{template:custom&amp;amp;#125; {{title=magic&amp;amp;#125;&amp;amp;#125;| Psionic,&amp;{template:custom&amp;amp;#125; {{title=psionic&amp;amp;#125;&amp;amp;#125; }" Basically replacing each &amp; with &amp;amp;
Turns out it's two levels of nesting that's required. value="?{Type of Attack| Magic,&amp;{template:custom&amp;amp;amp;#125; {{title=magic&amp;amp;amp;#125;&amp;amp;amp;#125;| Psionic,&amp;{template:custom&amp;amp;amp;#125; {{title=psionic&amp;amp;amp;#125;&amp;amp;amp;#125; }" But it works! I wonder what will happen when this bug is fixed. Will this continue to work or will it break?
1630962669

Edited 1630962986
GiGs
Pro
Sheet Author
API Scripter
When the bug is fixed, your current macros will stop working, and you'll need to remove either one or both levels of nesting. That's the bad news. The good news is that roll20 is planning to roll out a fix for this eliminating the need for html entities completely. When that eventually happens, macros like this will be much simpler.
1630969210
vÍnce
Pro
Sheet Author
Grinning Gecko said: Turns out it's two levels of nesting that's required. value="?{Type of Attack| Magic,&amp;{template:custom&amp;amp;amp;#125; {{title=magic&amp;amp;amp;#125;&amp;amp;amp;#125;| Psionic,&amp;{template:custom&amp;amp;amp;#125; {{title=psionic&amp;amp;amp;#125;&amp;amp;amp;#125; }" But it works! I wonder what will happen when this bug is fixed. Will this continue to work or will it break? You might test this on the Dev and see if you need to make the substitutions at all.&nbsp; I thought the Dev code base had this(nested queries and nested quotes...) worked out, but I could be wrong.