Copy link to clipboard
Copied
I'm working on a RPG character sheet..
I'm trying to calculate a characters total armor class..
I have all the fields set up and labeled..
The total AC bonus = 10 + DEX mod+ proficiency bonus +item bonus..
I have a field that already calculates and generates the "DEX Modifier" field.
The problem is, if you wear a suit of armor it allows you to add your Dex modifier to the ac total
BUT only upto the armors max..
Let's say you wear leather, it allows you to use only +4 max bonus.
So if I have a Dex mod of say +5 it needs to only add the +4 ..
My fields in question is "Dex modifier",
"Ac Dex modifier", " ac Dex modifier max"
I've tried
var A = this.getField("DEX Modifier").value;
var B = this.getField("ac Dex mod max").value;
If (A>B) {event.value = B}
So if ac Dex mod = Dex mod,
But if the Dex mod is greater than the ac Dex mod max, the Dex mod @= ac Dex mod max
Any help is greatly appriciated
Try this:
var A = Number(this.getField("DEX Modifier").valueAsString);
var B = Number(this.getField("ac Dex mod max").valueAsString);
if (B>0 && B<A) event.value = B;
else event.value = A;
Edit: code fixed
Copy link to clipboard
Copied
Your description is not very clear, but it seems you just want to apply the lower of the two numbers to the field. Is that it?
Copy link to clipboard
Copied
Basically, the field "AC DEX MOD" equal the field
"DEX MODIFIER".
if "DEX MODIFIER" is greater than the field
"AC DEX MOD CAP"
Then "AC DEX MOD" is equal to
"AC DEX MOD CAP"
If no value in the "AC DEX MOD CAP" field,
Then"AC DEX MOD" is equal to
"DEX MODIFIER
Example:
Dex modifier is +5,
The Dex mod cap is +4.
It will add only +4 in the ac DEX mod field
But if ac Dex mod cap field is empty,
Then AC Dex mod is equal to Dex modifier.
Hope that makes it clearer.
Copy link to clipboard
Copied
That doesn't cover all possible scenarios, though.
What if "Dex mod cap" is larger than "Dex modifier"?
Copy link to clipboard
Copied
Then it will add the "Dex modifier".
The AC Dex mod field should display the full Dex mod let's say +5.
But if the "ac Dex mod cap" has a value and is a lower value let's say only +4, then the AC Dex mod field should show +4 (in other words equal the AC Dex mod cap value)
Copy link to clipboard
Copied
Try this:
var A = Number(this.getField("DEX Modifier").valueAsString);
var B = Number(this.getField("ac Dex mod max").valueAsString);
if (B>0 && B<A) event.value = B;
else event.value = A;
Edit: code fixed
Copy link to clipboard
Copied
It's giving me
syntax error missing; before statement
3: at line 4
Copy link to clipboard
Copied
Sorry, small typo. I fixed it in the original post.
Copy link to clipboard
Copied
Thank you for your help, that did indeed make it work, outstanding.
Thank you again