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

Marcos and math

1493072447

Edited 1493072583
So I have a limited amount of experience with programming and I can't seem to get a handle on writing macros for this site. What I am trying to do isn't complicated for the player just tedious.  The goal here is to roll and display dice with modifiers, then find and display the average of those rolls. I can do this somewhat with the following macro: [[ ?{Dice1| } + ?{modifier1| } ]] [[ ?{Dice2| } + ?{modifier2| } ]] [[ round( [[ ( [[ ?{Dice1| } + ?{modifier1| } ]] + [[ ?{Dice2| } + ?{modifier2| } ]] ) / ?{Divisor} ]] ) ]] The problem is that I won't always know the number of dice / modifiers sets that the player will want to roll. It will be between 2 and 10. Above is for 2 dice / modifier sets and below is for 4: [[ ?{Dice1| } + ?{modifier1| } ]] [[ ?{Dice2| } + ?{modifier2| } ]] [[ ?{Dice3| } + ?{modifier3| } ]] [[ ?{Dice4| } + ?{modifier4| } ]] [[round([[([[?{Dice1|}+?{modifier1|}]]+[[?{Dice2|}+?{modifier2|}]]+[[?{Dice3|}+?{modifier3|}]]+[[?{Dice4|}+?{modifier4|}]])/?{Divisor}]])]] I would like to write a general macro that allows the user to define how many dice / modifier sets they would like to roll. If I was using a language like C++ I would use an array and loop but I am not sure how to accomplish this on roll20.  Any advice would be appreciated. Thanks. 
1493072931
Lithl
Pro
Sheet Author
API Scripter
You cannot roll a die and reference that result later in your macro with the basic dice engine. An API script could accomplish this, but that requires that the campaign's creator has a Pro subscription.
1493073329

Edited 1493073394
Ah, I actually didn't notice that the rolls didn't line up. So I would be using just: [[ ( [[ ?{Dice1| } + ?{modifier1| } ]] + [[ ?{Dice2| } + ?{modifier2| } ]] ) / ?{Divisor} ]] I am guessing I would also have to upgrade to Pro to allow me to do loops too? What language do you use for API scripts?
1493074186
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The API uses JavaScript. I think you could do what you want to do by nesting roll queries and using advanced roll queries. Your first level query would be how many sets, the nested queries would be the macros you already showed. <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>
Oh, I must have missed that section when I was reviewing the page. I'll see if I can't work it out.&nbsp; Thank you.&nbsp;