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

Defining an attribute in a character sheet from the highest of two variables

September 22 (8 years ago)
So I'm trying to define an attribute for a roll on a character sheet I am working on, but the number won't display regardless of what I do, and I am running out of ability to think coherently trying to figure it out. Can anyone offer some advice?

input type="number" name="attr_save_physical" value="{@{strBonus},@{conBonus}}kh1+@{PhysProf}"

Essentially I need it to keep the highest of Strength or Con modifier, and add it to another modifier to produce the attribute result.
September 22 (8 years ago)

Edited September 22 (8 years ago)
There needs to be a dice expression in the function in order for it to work.
See Grouped Rolls

Try this [[ {@{strBonus}+0d0 ,@{conBonus}+0d0 }kh1+@{PhysProf} ]]

Inline rolls might be a good idea too, try it with and without to see what you prefer. 
September 22 (8 years ago)

Edited September 22 (8 years ago)
Thanks for the try, but this still is not working. The number still refuses to display. This is enormously frustrating. For clarification, this is intended to be a disabled input that auto-calculates based on the stat bonuses. I'm not sure if that was clear or not.
September 22 (8 years ago)
Dice expressions don't work inside character sheet input element values. "Note that you can only include attributes from the current Character. You also can't include macros, abilities, or rolls...just basic math such as@{Intelligence}/2+@{Level}. You also have access to the floor, round, and ceil functions, such as floor(@{Intelligence}/2)."

I don't see a way to do this without the API.
September 22 (8 years ago)
Son of a... That seems like an oversight of design, but then I suppose it is a bit of a niche. Thanks.
September 22 (8 years ago)
Aye
September 22 (8 years ago)
Diana P
Pro
Sheet Author
You can do math only max and min values:

If x > y, the result is x, while if x < y, the result is y
<input type="hidden" disabled="true" name="attr_max_xy" value="(((@{x} + @{y}) + abs(@{x} - @{y})) / 2)" />

(pulled from: https://app.roll20.net/forum/post/882997/css-wizar... )

Several existing character sheets use these tricks to calculate things.  There are some functions which are more difficult to implement, but max is easily doable. :)


September 22 (8 years ago)
I knew there had to be a formula for this!
September 22 (8 years ago)

Edited September 22 (8 years ago)
Lithl
Pro
Sheet Author
API Scripter
Also, a number of the hurdles presented for autocalc fields are easily answered with sheet workers. For example, the same autocalc that Diana posted can be achieved like this:
<input type="number" name="attr_x">
<input type="number" name="attr_y"> <input type="number" name="attr_max_xy" readonly>
<script type="text/worker"> on('ready change:x change:y', function() {
getAttrs(['x', 'y'], function(values) {
var x = parseInt(values.x) || 0,
y = parseInt(values.y) || 0;

setAttrs({ max_xy: Math.max(x, y) });
});
});
</script>
My post Diana linked to was from a time when sheet workers were not a thing. =)

In this case, the autocalc version is shorter (if harder to read, IMO), but other parts of that post (such as the trancendental functions) get shorter, easier to read, and more accurate with sheet workers.
September 23 (8 years ago)

Edited September 23 (8 years ago)
Diana, that is pretty much exactly what I need, but will it work if the values are equal, or will it freak out? Also, does anyone in this thread have any experience with conditional statements?
September 23 (8 years ago)
Diana P
Pro
Sheet Author
It will work if they are equal.

What kind of conditional statements are you looking for?  (i.e. maybe.... :)
September 23 (8 years ago)

Edited September 23 (8 years ago)
I'm trying to make a conditional wherein if the given value is greater than or equal to 0, use(add) an extra value, else use(add) 0. I've been trying to follow the instructions on the wiki but only ended up making my head hurt.

Edit: Nevermind, thank you all for your assistance, but my wife figured it out for me.
September 24 (8 years ago)
Care to share your wife's solution?
October 23 (8 years ago)

Edited October 23 (8 years ago)
Her solution was:

({{@{X},-1}>0}*(@{Y}+0)+0)

Where Y is the value of a given Skill, and X is the character's Proficiency Bonus. If Y is 0 or greater, it adds the Proficiency Bonus to the result of the roll. If it is not, it adds nothing.

Sorry it took so long. I am godawful at checking these things.