• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with if then code

Explorer ,
Jul 31, 2019 Jul 31, 2019

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

TOPICS
Acrobat SDK and JavaScript

Views

602

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 01, 2019 Aug 01, 2019

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

Votes

Translate

Translate
Community Expert ,
Aug 01, 2019 Aug 01, 2019

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2019 Aug 01, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2019 Aug 01, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2019 Aug 01, 2019

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2019 Aug 01, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2019 Aug 01, 2019

Copy link to clipboard

Copied

It's giving me

syntax error missing; before statement

3: at line 4

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 01, 2019 Aug 01, 2019

Copy link to clipboard

Copied

Sorry, small typo. I fixed it in the original post.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 01, 2019 Aug 01, 2019

Copy link to clipboard

Copied

LATEST

Thank you for your help, that did indeed make it work, outstanding.

Thank you again

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines