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

Equivalent of a Variable in a Macro?

Hi everyone, I'm a Roll20 Noob, and I am needing some help with a macro I am building.  How can I can have a macro assign the result of a specific auto dice roll to a 'variable' so that value can be used multiple times in different parts of the macro?  For example, I am building a macro to help create Pre-Rolled PCs for my games.  I want to have a fair random distribution of heights & weights.  To keep things from being too crazy, I need to link the height to the weight, but also allow for some bounded randomness.  For example, with a Human female, I can get a random height by [[1d18+55]] in. which will give me a height which is 4'7" to 6'1" tall.  But if I then use another completely random calculation for the weight, I can end up with a 4'7" female weighing 245lbs.  Possible, but far more unlikely than what is coming up.  I have been trying to use a modified BMI calculation, but it requires knowing the height, and so far I have not figured out how to assign the 1d18+55 roll to a variable name.  I sure there must be a way because it works for Query Rolls since Query Name can be referenced multiple times with always the same value.  But how do you assign a value to a placeholder without a Query?
1609993919
GiGs
Pro
Sheet Author
API Scripter
Roll20 macros cant save the result of a roll to a variable, unfortunately.  there are two ways you can get what you want, one easier than the other. Both require a Pro subscription, which you have. The hard way: write a custom API script to do the calculation. The easier way: use two separate macros and the API script ChatSetAttrs.      The first macro, you'd roll the hight and use chatSetAttrs to save it to an attribute on a character sheet.     The second macro would read that height from the character sheet, perform your calculation, and give you the weight (which you can save directly to a character sheet using chatSetAttrs).     Note that this does require two separate macros. You run the first one, then run the second-  you can't combine them due to the way roll20's Order of Operations.
Thanks!  I'll give it a try.
1610173727

Edited 1610173768
Kraynic
Pro
Sheet Author
Depending on how the calculation is done, this might be a time the ability to display the result of an individual roll/calculation might work. [[[[1d8+55]] whatever calculation uses the height in inches here]] pounds $[[0]] inches <a href="https://wiki.roll20.net/Reusing_Rolls" rel="nofollow">https://wiki.roll20.net/Reusing_Rolls</a>
That's great!&nbsp; I read the links and your suggestion.&nbsp; Then some patient testing and got: /w gm &amp;{template:default} {{name=Human}} {{Age: [[1d10+18]] (Male [[round([[([[1d18+60]]**2)]]*[[(1d40/10+20)/703]])]] lbs and $[[1]] inches tall.) (Female[[round([[([[1d18+55]]**2)]]*[[(1d40/10+20)/703]])]] lbs and $[[4]] inches tall.)}} Thanks again!
1610249794
GiGs
Pro
Sheet Author
API Scripter
If you want to break that up for easier reading this should work /w gm &amp;{template:default} {{name=Human}} {{Age=[[1d10+18]]}} {{ Male=[[round([[([[1d18+60]]**2)]]*[[(1d40/10+20)/703]])]] lbs and&nbsp; $[[1]] inches tall.}} {{Female=[[round([[([[1d18+55]]**2)]]*[[(1d40/10+20)/703]])]] lbs and&nbsp; $[[4]] inches tall.}}
1610249822
Kraynic
Pro
Sheet Author
Nice!
That's a great edit, GiGs!&nbsp; It does make it easier to read.&nbsp; I still have a lot learn on the nuances of the Macros, much less the API scripts.&nbsp; The remainder of the macro calls a number of rolling tables in which I have other characteristics, such as eyes, hair, skin color, as well as languages, background, etc.,&nbsp; My goal is to have my NPCs and Pre-Rolled PCs as randomly generated as possible, as quickly as possible. I have gone through the online wiki helps for both, but all the lessons seem to assume the reader has a basic understanding of the overall macro structure and syntax.&nbsp; I last professionally programmed in 1996 (moved into network design instead), so a lot has changed since then.&nbsp; Can either of you recommend a good 'Dummies Guide' on Roll20 Macro &amp; API structures?&nbsp; I always do best when I understand the overall architecture and logic, instead of unlinked puzzle pieces....
Final version (including roll tables): /w gm &amp;{template:default} {{name=Human}} {{Age=[[1d10+18]] Eyes:[[1t[Human-EyeColor]]]}} {{Hair=[[1t[Human-HairColor]]]}}&nbsp; {{Skin=[[1t[Human-SkinColor]]]}} {{Male=[[round([[([[1d18+60]]**2)]]*[[(1d40/10+20)/703]])]] lbs and&nbsp; $[[4]] inches tall.}} {{Female=[[round([[([[1d18+55]]**2)]]*[[(1d40/10+20)/703]])]] lbs and&nbsp; $[[6]] inches tall.}}
I based the equation around the BMI standard, plus height and weight ranges as specified by Forgotten Realms, with an element of randomness.&nbsp; I will be porting this over to the other PC races as well.