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

Adding the result of two different roll queries in a template

1641813529

Edited 1641813689
Hello, first time macro coder here, I'm trying to code a specific behaviour for our tabletop game. What I'm trying to achieve: I'm trying to prompt a user with two different roll query to select two attributes , showing in a template the single rolls for each query and then their total sum. The important thing is that our 4 main attributes for a character are not based on simple numbers, but on dice dimensions , so for example: Attribute Int : d6/d6 Con: d10/d10 So each time a character must roll the corresponding current dice size during a Attribute test and see the result. What I've tried till now:  I'm trying to fit everything in a roll template but I'm utterly failing to sum the result of the roll queries no matter what, I'm doing this macro within a char sheet to lower the code needed. &{template:default} {{name=TEST}} {{First=?{First|Int,[[ @{Int}[int]]] |Vig,[[ @{Con}[con]]] } }} {{Second=?{Second|Int,[[ @{Int}[int]] |Vig,[[ @{Con}[con]]] } }} {{ Total = [[ ?{First} + ?{Second} ]] }} This macro correctly execute for first part, but in the last part instead of getting the result of the queries they get re-rolled with new values with the corresponding selected dices. In this image the First is a d6 and the Second is a d8 rolls, then the Total shows 9 instead of 8 because it re-rolls d6 and d8 for this: So there is a method to avoid query re-roll? Or I'm stuck with what I got here and make another different approach? Also why my purple text is not centered ?
1641819464
timmaugh
Pro
API Scripter
You'll want to 1) build the final roll first, 2) build it outside of the roll template structure (between parts), and 3) refer to the component parts by their roll marker index when you need them. &{template:default} {{name=TEST}} [[ ?{First|Int,[[ @{Int}[int]]] |Vig,[[ @{Con}[con]]] } + ?{Second|Int,[[ @{Int}[int]] |Vig,[[ @{Con}[con]]] }]] {{First= $[[0]]}} {{Second=$[[1]] }} {{ Total = $[[2]] }} As for why the purple is to the left, that's just the way the default template is styled. There is a way in the Tricks thread to insert some HTML, I think. Maybe someone else has the link right at hand, or I can try to find it.
This solution worked like a charm, I've seen some examples of external roll and then indexing but could not compute this approach to my problem. So the most external roll in a nested one is the last member of the indexing array of rolls for that line, while the first member is the innermost from left to right if I understood correctly. My humble thanks. 
1641849767
timmaugh
Pro
API Scripter
Excellent! And... about the rolls. It generally goes inner-most-left to outer-most-right in the numbering... but there has been some confusion about that. I have yet to run a comprehensive test to determine the exact rules. Easier just to put together a roll template with the right number of rolls for your output: &{template:default} [[...nested rolls...]] {{Roll0 = $[[0]]}} {{Roll1=$[[1]]}} {{Roll2=$[[2]]}} ... etc... Then hover over each part to see which one you need. =D
I have conducted some testing on this today while I composed some other macros/abilities and it's like you said , obviously sometimes I had to deploy every possible nested roll until I got the "inline roll error" to be sure of covering all rolls employed ( Basically I went "out-of-bound" of the indexing array) like you showed in this last example. So I'm quite confident that I've grasped this aspect of the engine, thanks again.