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

Re-using die rolls

Good morning I have a problem with a Macro in which I should re-using some die rolls in other calculations. I have already checked this post from the Wiki, but with no success. {{Charges= [[2d20]] }} {{Value=[[(?{Power (lvl)})*100*( $[[0]] )]] gp}} (There are HTML entities because the code is part of a nested query). I am using the BECMI character sheet and would like to use the 5eDefault template, if possible. What I would like to get is calculating Value by multiplying some value prompted by the user (?{Power (lvl)}), a fixed one (100) and the result of a previous dice roll (2d20 which I would call as $[[0]]). I have already tried to roll before the title of the template, in order to hide it, as explained in the Wiki, but it didn't work and it breaks the calculations. Any suggestions?
1616762478
Ziechael
Forum Champion
Sheet Author
API Scripter
Without seeing the full thing I can't accommodate the html requirements but this should be what you need (you can't perform mathematical operations on recalled roll ids: [[(?{Power (lvl)})*100*( [[2d20]] )]] {{Charges= $[[0]] }} {{Value= $[[1]] gp}}
Ziechael said: Without seeing the full thing I can't accommodate the html requirements but this should be what you need ( you can't perform mathematical operations on recalled roll ids : [[(?{Power (lvl)})*100*( [[2d20]] )]] {{Charges= $[[0]] }} {{Value= $[[1]] gp}} Then it's impossible to achieve what I need, since Value = Charges * the operation inside the first [[ ]]
1616772970
Ziechael
Forum Champion
Sheet Author
API Scripter
That's what $[[1]] should be outputting... the key is to perform your full equation first using nested inline rolls and then use the recall mechanic just for display. Feel free to share your entire macro if it isn't work as expected... I'm assuming you have another reference to ?{Power (lvl)} somewhere that has a default value or something to prevent it breaking the equation if it is left as null.
Ziechael said: That's what $[[1]] should be outputting... the key is to perform your full equation first using nested inline rolls and then use the recall mechanic just for display. I will look into it, then. The rest is, as you mentioned, a repetition of the same pattern.. &{template:5eDefault} [[2d20]] {{title=magic Objects}} {{subheader=Cosntruction Data}} {{outputall=1}} ?{Which kind of object?| Ring,(...)| Wand,{{Type=Wand}} {{Power (lvl)=?{Power (lvl)|1|2|3|4|5|6|7|8|9}}} {{Charges= $[[0]] }} {{Value=[[(?{Power (lvl)})*100*($[[0]])]] gp}} }
1616776243

Edited 1616776289
Ziechael
Forum Champion
Sheet Author
API Scripter
I'm not sure you need to have any nesting for this: &{template:5eDefault} [[(?{Power (lvl)|1|2|3|4|5|6|7|8|9})*100*([[2d20]])]] {{Charges=$[[0]]}} {{Value=$[[1]] gp}} {{title=Magic Objects}} {{subheader=Construction Data}} {{outputall=1}} {{Type=?{Which kind of object?|Ring|Wand} }} That seems to do the same thing... if you want the queries in a specific order you could: ! ?{Which kind of object|Ring|Wand}  ?{Power (lvl)|1|2|3|4|5|6|7|8|9} &{template:5eDefault} [[(?{Power (lvl)})*100*([[2d20]])]] {{Charges=$[[0]]}} {{Value=$[[1]] gp}} {{title=Magic Objects}} {{subheader=Construction Data}} {{outputall=1}} {{Type=?{Which kind of object} }}
Ziechael said: I'm not sure you need to have any nesting for this: &{template:5eDefault} [[(?{Power (lvl)|1|2|3|4|5|6|7|8|9})*100*([[2d20]])]] {{Charges=$[[0]]}} {{Value=$[[1]] gp}} {{title=Magic Objects}} {{subheader=Construction Data}} {{outputall=1}} {{Type=?{Which kind of object?|Ring|Wand} }} That seems to do the same thing... if you want the queries in a specific order you could: ! ?{Which kind of object|Ring|Wand}  ?{Power (lvl)|1|2|3|4|5|6|7|8|9} &{template:5eDefault} [[(?{Power (lvl)})*100*([[2d20]])]] {{Charges=$[[0]]}} {{Value=$[[1]] gp}} {{title=Magic Objects}} {{subheader=Construction Data}} {{outputall=1}} {{Type=?{Which kind of object} }} That is very interesting,  think I can really use something like that. I am only confused by that ! at the very beginning of the code: is it there by mistake or does it have a specific purpose?
frons79 said: I am only confused by that ! at the very beginning of the code: is it there by mistake or does it have a specific purpose? The ! creates a fake API (script) command.  Without the !, the first queries would print out the results in the chat.  Any time you have a duplicate query in a macro, the output/result will always be the same as the first time it is called.  That's why in the macro Ziechael gave you ' ?{Which kind of object ' is listed twice, but only the first time has the output options ' |Ring|Wand ' listed.  When the query is called the second time, it automatically uses the same response from the first call.  But because the first call was a fake API command, it doesn't get printed into the chat the first time it's called. So that allows you to put the order the queries are asked in any order you want, by putting them all on a single line after a !.
That is very kind. Thanks to both of you for starters, it will help me a lot!