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

Pythagorean Macro?

Still getting my head around writing macros, but this is one I can't seem to find anywhere, and would be very useful. I currently run it in an excel sheet, but I would prefer an in-game solution. Baba Lysaga is in her floating skull 60 feet in the air. The player is 20 feet from the point on the ground she is hovering over. How far is the player from Baba Lysaga? Looking to write a macro where I supply A and B, and it crunches A^2+B^2 and gives me C I have figured out how to create a prompt to collect/report the values A and B ( =?{A} ?{B})   Is there a way once I have collected those values that I can reference them in equations? That's the piece I am missing. also is there syntax I can use to collect both values in a single prompt? Curently one prompt opens, then another. Not a huge deal but I'd like to clean it up if I can.  If this has already been answered elsewhere please feel free to just point me to it, But I havent seen anything in my google-fu. Maybe it can't be done but it seems like it should be pretty basic.
1646153986
David M.
Pro
API Scripter
I haven't used it, but you may want to check out the measure script (on one-click), though it will probably only calculate in 2D. If you need to do something with that distance (e.g. conditional effects), then the scriptcards api script can also perform measurements and use them
1646156435

Edited 1646157125
You can use this directly in chat: [[ [[ [[?{A}**2]] + [[?{B}**2]] ]]**0.5 ]] Or if you want to get fancy (I borrowed the decimal portion from GiGs - thanks!): $[[0.computed]]&amp;sup2; + $[[2.computed]]&amp;sup2; = [[ round([[ [[[[?{A}]]**2]] + [[[[?{B}]]**2]] ]]**0.5*10)/10 ]]&amp;sup2; <a href="https://wiki.roll20.net/Dice_Reference#Math_Operators_and_Functions" rel="nofollow">https://wiki.roll20.net/Dice_Reference#Math_Operators_and_Functions</a>
1646156593
GiGs
Pro
Sheet Author
API Scripter
You can use ** to denote powers, so this works: [[ round((?{X|1}**2 + ?{Y|1}**2)**.5)]] The round part can be deleted if you arent interested in decimals, or if you want only tenths, you can use: [[ round((?{X|1}**2 + ?{Y|1}**2)**.5*10)/10]]
1646156696
GiGs
Pro
Sheet Author
API Scripter
Steve G. said: is there syntax I can use to collect both values in a single prompt? Curently one prompt opens, then another. No, this is unfortunately not possible, Every query creates its own prompt. It would be really nice if roll20 collected all prompts and put them on one dialog, but there's no way to do that.
1646156816

Edited 1646157017
GiGs
Pro
Sheet Author
API Scripter
Jarren, whats &amp;sup2 doing in your answer? I'm not familiar with that expression. Aha, I see - its showing a superscript. Nice.
1646156908

Edited 1646157156
GiGs said: Jarren, whats &amp;sup2 doing in your answer? I'm not familiar with that expression. The fancy part that inserts a 'squared' superscript. Like this:&nbsp; ² I made a couple edits and posted a screenshot.
1646159856
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
These macros are very useful, but just in case it saves you time and headache, diagonals are counted as 1 in 5e. Technically, this should be true for any plane of reference. Therefor the Pythagorean theorem in 5e should be H =&nbsp;a∨b or H = max{a,b}, or colloquially, "the length of the hypoteneuse of any right triangle is equal to the greater of the two other sides." Technically, the answer to your question above is "60 feet". I know this doesn't make sense, and it's not actually what you are asking for, but it is consistent with the implied geometry of 5th edition D&amp;D.
I have a genius method to figuring out angles in roll20.&nbsp; I purposely warn the players in session zero that I suck at math and unless someone does the math for me, you are likely getting bad math rulings from me.&nbsp; Ever since then, the players do the math for me and even use a google calculator for pythagorean theorem lol.&nbsp;&nbsp;
DM Eddie said: I have a genius method to figuring out angles in roll20.&nbsp; I purposely warn the players in session zero that I suck at math and unless someone does the math for me, you are likely getting bad math rulings from me.&nbsp; Ever since then, the players do the math for me and even use a google calculator for pythagorean theorem lol.&nbsp;&nbsp; Haha just don't be surprised when this happens: GM: "Are you close enough to hit the enemy?" Player: "Yes, because of the Pythagorean Theorum, it's within the 30 feet range of my attack." GM: "Ok, after that the enemy uses his attack which is also a 30 foot range." Player: "Umm but because of the transverse axis of angle vis a vis the rotation of the planet compared to the distance from my character along a vertical plane, it's farther to come back that direction, so the enemy is too far away."
Thanks for all the input everyone! this is all immensely helpful!