Skip to main content
Known Participant
August 1, 2019
Answered

Help with if then code

  • August 1, 2019
  • 1 reply
  • 1049 views

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

This topic has been closed for replies.
Correct answer try67

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)


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

1 reply

try67
Community Expert
Community Expert
August 1, 2019

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?

Known Participant
August 1, 2019

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.

try67
Community Expert
Community Expert
August 1, 2019

That doesn't cover all possible scenarios, though.
What if "Dex mod cap" is larger than "Dex modifier"?