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

Clamping values between two numbers.

1554174320

Edited 1554174357
AndrielChaoti
API Scripter
There's a way to do this with macros, and I fgiured I'd be nice and share it. I use this in my games as a way for players to get that oldschool CRPG style health reading for a monster based on it's HP... Here's the basic structure of the macro: {[[{<upper bound>, <value under test>}kl1]], <lower bound>}kh1 Replace the values in <> with whatever you need them to be... Here's that HP macro I was just talking about, select the target after running the macro, and voila, you get a # back corresponding to the token's current health, fixed between a range of 0-5. {[[{5, floor((@{target|Target|hp} / @{target|Target|hp|max}) * 5)}kl1]], 0}kh1 Edit  There is one thing I'd like this macro to do, and that's show a text value based on the outcome of the above formula, if that's at all possible.
1554175710
GiGs
Pro
Sheet Author
API Scripter
AndrielChaoti said: Edit  There is one thing I'd like this macro to do, and that's show a text value based on the outcome of the above formula, if that's at all possible. Unfortunately that's not possible without the Pro-level API.
1554264725

Edited 1554266030
Ziechael
Forum Champion
Sheet Author
API Scripter
Well... depending on how much time/effort you are willing to put into it you could create a rollable table for every potential value. Each table would be named as the result of the macro and the only entry in the table would be the text you want to display: So, for your use case you'd call it like: [[ 1t[[[ {[[ {5, floor(([[ @{target|Target|hp} ]]/[[ @{target|Target|hp|max} ]])*5) }kl1 ]], 0}kh1 ]]] ]] Depending on the number of potential results I wouldn't recommend this approach... just putting it out there as a possible workaround ;) edit: It does not want to play nice with attribute calls however... flat values are fine, attributes are proving trickier, GiGs may be right with them (as always...) edit 2: Ok, it does work... updated example above... will silently fail if a table with the right name doesn't exist though... to test for that use version 2 below: /r 1t[[[ {[[ {5, floor(([[ @{target|Target|hp} ]]/[[ @{target|Target|hp|max} ]])*5) }kl1 ]], 0}kh1 ]]]
1554274578
GiGs
Pro
Sheet Author
API Scripter
Hehe, thanks for the compliment, Ziechael. That's a clever approach, having a bunch of single entry tables. If the range is limited to 0 to 5, it's not that laborious to create.