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

Macro to obtain the sum and the highest roll of two dices

Hello again a inexpert macroer here, today I was thinking how to code a specific macro for automate our table top attack/damage mechanic and I could not manage to understand how to develop a right solution. What I want to achieve:  Our table top game has the following mechanic for rolling hits and damage with weapons/abilities: Every character statistics are in a form of dice sizes ( d6, d8 etc.) so the weapons / abilities uses those dices to confirm a hit and subsequently the calculation of damage, here is a concrete example Long sword hits if [ Dex roll + Con roll ] > Enemy Defense value , if hit is confirmed roll damage as [ Highest roll of two stats + 3 ] So my objective is to deploy a macro that alongside a template (Default one) shows One row : first roll result + second roll result = total of sum for the hit Second row: highest of the two rolls + fixed number = total damage What i tried till now:  I tackled only half of the problem, I can with no problem complete the code for the one row to show the result with a in line roll like this ...various template code...[[ [[ @{dex}[dex] ]] + [[ @{con}[con] ]] ]] {{ Hit value= $[[0]] + $[[1]] == $[[2]]}} But now I'm stuck with the second row, I've read the Dice Reference for all possibile tools , especially regarding the success rolls against a value and the keep the highest rolls; but I fail to apply them to my problem and cannot find a way to nest these tools in my roll without breaking the first row, for instance: If I try to implement the Keep High in the following form: [[ {[[ @{dex}[dex] ]] + [[ @{con}[con] ]]}kh1 ]] I lose the total sum since one dice is dropped so the first row indexing is broken From my research on forum I cannot use the index in any calculation so I cannot do a thing like this [[ [[ @{dex}[dex] ]] + [[ @{con}[con] ]] ]] {{ Hit value= $[[0]] + $[[1]] == $[[2]]}} {{second row=[[ {$[[0]],$[[1]]}kh1 + 3 ]] }} Is there any way to tackle down this problem of mine? I do not have access to the API but my GM does have it , in the case that this problem requires API scripting how could I tackle it ?
1641921492
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Unfortunately, that's a little beyond the base dice roller's ability. I think that an API script, or a full custom character sheet with a roll template are you options. The API method I believe that Timmaugh's Meta scripts could probably do this for you, although he'd need to describe how they'd do it (paging Tim!).
Understandable , the engine cannot suit every single need of every game types, I guess that I must delve into API scripting from the GM side. I'll look around for Info on Tim scripts on the web, also I'll delve onto a custom sheets/template possibile solutions, thanks you for your insight.
1641924028
timmaugh
Pro
API Scripter
Yep, the meta toolbox can make quick work of this. Since you want to re-use the roll index, you need to slow down the roll where they would be used so the value can be extracted. That should be all available just using ZeroFrame... Your second line of the template would look like: {{second row = [\][\] {$[[0]].value,$[[1]].value}kh1 + 3 \]\] }} Then you have to start your normal template statement with an exclamation point (to get it go to the API), and include a {&simple} (to get it to be spit back out again)... !&{template:default} ... {&simple} Since I don't have the stats set up the way you have them set up, I just mocked it up using two rolls, but the concept is the same: !&{template:default} [[ [[1d10]] + [[1d8]] ]] {{name=Roll Proof of Concept}}{{ Hit value= $[[0]] + $[[1]] == $[[2]]}} {{second row = [\][\] {$[[0]].value,$[[1]].value}kh1 + 3 \]\] }} {&simple}
1641925143
David M.
Pro
API Scripter
Note this requires a Pro account for the owner of the game in question. 
1641933374

Edited 1641933460
A very interesting take on how the engine works, if I understood the concept basically we are delaying the execution of the roll engine(with the [\][\] ) just in time to extract a property of the roll ( Html? ) with the pipe `.value` from the index  array , so that can be actually accepted as a computable value from the same engine (which is still "hanging" ) and then finally we let the engine "go" again with the "simple" call. I'll have to wait to test this to make sure it works for us , but if it does I will come back to post result. For David: yes I'm aware, I don't remember which of the two tier my GM have but I'm somewhat sure he can access the API at least on his side.
1641936176
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Good luck Luca! Tim's Meta scripts are extremely powerful. As a reminder/expansion, your GM will need to install zeroframe from the one-click drop down on their api scripts page. They'll have access to this page if they have a green "pro" badge like David and Tim do.
1641971050
GiGs
Pro
Sheet Author
API Scripter
Oosh had a post recently where he found that you could use $[[0]].computed in calculations (I think that was the syntax). More detail might be in the useful tips & tricks thread - but you might be able to use this to construct your formula without a script.
Thanks Scott I'll keep those tips in mind,  but seems I've already hitted another wall. Well bad news we have only a plus subscription, so API access for now is forbidden. Dear Gigs , I think I've seen the post before where the pipe computed were called on index calls, I'll scroll in the tip and tricks forum topic for aore detailed information. So I'm planning going pro , I was checking the feature and my only doubt is this :  Shared table features API access So if I as a player have the Pro account can I share the scripts which access the API to the other free tier players ? Alternatively can those player write a macro in their sheets that access the API?
1641992128
timmaugh
Pro
API Scripter
The API access is driven from the owner of the game, and that's the only subscription level that matters as far as API access. If the game owner has a pro sub, then any GM can add/import/install a script, any GM can reboot the sandbox, and any player can make use of installed scripts.
1641992312
Andreas J.
Forum Champion
Sheet Author
Translator
More about Oosh's trick: <a href="https://wiki.roll20.net/Reusing_Rolls#Computed_rolls_and_order_independence" rel="nofollow">https://wiki.roll20.net/Reusing_Rolls#Computed_rolls_and_order_independence</a> <a href="https://wiki.roll20.net/Macro_Guide" rel="nofollow">https://wiki.roll20.net/Macro_Guide</a> have organized and linked all tricks from the "tips &amp; tricks"-thread, and can be easier to navigate and find what you're looking for. So if I as a player have the Pro account can I share the scripts which access the API to the other free tier players ? If the creator of a game has active Pro subscription, all users in their games can use whatever APIs are installed in them. can those player write a macro in their sheets that access the API? Yes, but do note that some APIs have settings you need to change to allow players full access. It's pretty common that API scripts by default only allow GM to use all commands, while players might be partially or completely limited. This differs from API to API. If you take a look at <a href="https://wiki.roll20.net/Player#API" rel="nofollow">https://wiki.roll20.net/Player#API</a> , you can see a list of API that enable players to edit things in a game they normally can't.&nbsp;
Thanks Tim and Andreas for your answer and link reference Regarding the use of computed values I'm sad to say that I could not find a use in my problem, from testing I understood that a .computed &nbsp;attribute simply tells the interpreter of the engine that the value of index that is referenced in that particular position is a future value coming from a inline roll and should not be processed as text immediately but has to wait for the roll. Basically it's somewhat like the Javascript Promises or Java Generics, I promise you a value but wait until I get that. Here is the test code and image for reference, the non .computed &nbsp;references breaks the nested rolls. &amp;{template:default} {{name=Test}} [[ [[ 1d10 ]] + [[ 1d6 ]] ]] {{External roll with indexing= $[[0]] + $[[1]] =$[[2]] }} {{ Inline roll with indexing without computing= $[[3]] + $[[4]] = [[ [[1d10]] + [[1d20]] ]] }} {{ Inline roll with indexing with computing= $[[5.computed]] + $[[6.computed]] = [[ [[1d10]] + [[1d20]] ]] }} In the end .computed &nbsp;values still behaves like the indexed &nbsp;ones regarding inline calculations usage, they cannot be used , so if i try : {{ damage = [[ { $[[0.computed]] , $[[1.computed]] }kh1 ]] it does not work and shows in the template as: Damage = [[ { roll value in yellow, roll value in yellow } kh1 ]] Before concluding thanks to you all for support , truly amazing community.