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

Storing Variables in a macro

I'm trying to make a Conjure Animals macro for 5e, and I've got as far as asking for number of hits and attack bonus, rolling against the tokens AC, checking successes and rolling that many sets of dice for damage.

The issue lies in that most creatures deal 'X'd'Y'+'Z' damage on hit. 'X' and 'Y' are easy enough, its already set up to roll [[success*{dice}]]d{size}, but I need a way to roll [[success*dice]]d{size} + [[Success*{Flat}]]

I can't just copy the success part of the code to both sides, as it will roll independently both times, I need Success to be the same on both sides.

I think I need a way to store variables, to set success to var x, so I can then /r [[x*{Dice}]]d[[x*{Flat}]], however if I ought to be doing it another way I'd love to hear that either.
Thanks in advance.

January 10 (4 years ago)
Jordan C.
Pro
API Scripter

You can't store variables with vanilla macros, unfortunately. You can return the result of a previous roll but you cannot perform any further operations on that. 

That being said, this is the closest I could get where it shows the total damage as two separate numbers (numbers hardcoded for testing):

[[ [[ [[ 4[Successes]*3[Flat] ]] / 3[Flat] ]]d8[Size] ]] + $[[0]]

Which in a template like this:

&{template:default} {{name=Results}} {{Damage:=[[ [[ [[ 4[Successes]*3[Flat] ]] / 3[Flat] ]]d8[Size] ]] + $[[0]]}}

Returns this:


January 10 (4 years ago)

Edited January 10 (4 years ago)

Ok, so I cannot, in a macro, roll for successes and preform two operations on that result.
Macro's also do all modifiers at once, right? So I can't roll for success, ask for manual input of the result, then roll damage in the same macro.

If I were to simplify the problem, is there a way to roll for successes against a targets ac
/r  ?{NumOfHits#|1}d20>[[@{target|foe|npc_AC}-?{HitBonus#|0}]] 

And then roll that many 3d4+1's by using the previous roll as an input
/r 3*$[[0]]d4+$[[0]]

The end goal is to automate as much as possible out of rolling an arbitrary number of d20's against a target number, then roll that many (damage) sets. If I have to, everything but the number of d20's I'm happy to hardcode, making a new macro for each creature

Edit: Are there any work arounds for writing to variables. I noticed there was tools for reading bars, no tools to write? or to write to an attribute?

January 10 (4 years ago)
Jordan C.
Pro
API Scripter

I'd have to revisit the overall process when I get a chance but to answer the edit, you cannot write values without the API (requires pro subscription perk for the game creator)

Alright, Thanks for the help!

For now I'll just make two macro's, One to generate successes, and one to manually enter successes.

January 10 (4 years ago)
David M.
Pro
API Scripter

I believe I saw a hacky way somewhere to simulate a variable by sending results to the turn tracker and having a second macro reference the tracker value. But yeah, without api you're going to be limited. 

January 10 (4 years ago)
Pat
Pro
API Scripter


David M. said:

I believe I saw a hacky way somewhere to simulate a variable by sending results to the turn tracker and having a second macro reference the tracker value. But yeah, without api you're going to be limited. 


Yeah, I think I threw that hacky way up there, but it requires two macros and not all at once, because of the way JavaScript is single-threaded, and how writing to the turn tracker and to the chat work. 

January 11 (4 years ago)
David M.
Pro
API Scripter

Ha, perhaps clever would have been a more appropriate adjective :) but as you mentioned the actual use is kind of hacky due to non-pro account limitations.

Speaking of hacky solutions, the following handles your Xd4+X problem (where X is the number of successful hits). Exploits the re-using dice rolls trick, similar to and expanding upon what Jordan wrote above.

&{template:default} {{name=Re-use die roll example}} {{Total Damage=[[ [[?{NumOfHits#|1}d20>[[@{target|foe|npc_AC}-?{HitBonus#|0}]] ]]d4 ]]+$[[1]]}} {{Num Attacks=[[?{NumOfHits#}]]}} {{AC=[[@{target|foe|npc_AC}]]}} {{To-hit Bonus=[[?{HitBonus#}]]}} {{Modified Target=$[[0]]}} {{Num Succeses (Rolls) =$[[1]]}}
Caveat is that you must display the total damage roll first, and will have to add the +X part in your head, since you can't perform math operations on a re-used die roll. By detailing the individual rolls in the template, you can mouse over each one to see the actual rolls.
Here is the output:

To handle the original problem of adding a non-unity multiple of the number of successes (e.g. NumSuccesses*3) to the total damage, it may be possible to implement a formula such as GiGs described in this post. This might allow a true final summation, as well, but would take some more thinking.
January 11 (4 years ago)
Pat
Pro
API Scripter


David M. said:

Ha, perhaps clever would have been a more appropriate adjective :) but as you mentioned the actual use is kind of hacky due to non-pro account limitations.

"Hacky" is the right word, because I'm abusing something to get to something you aren't supposed to be able to do :)