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

If x then y for a Custom Character Sheet for Table Top RPG Game

Community Beginner ,
Jun 09, 2021 Jun 09, 2021

Hello all,

I am in the process of creating a Custom Character sheet as a PDF form using Acrobat Pro X but I need a Javascript that will help me fill in some cells properly.

 

I want a modifier (Ability Mod) that shows to be generated from the Ability Score. When I say that, what I mean is the characters get a bonus (or negative in some cases) to things they do depending on their Ability Score. Like, if a Character has a score of 15 for their Strength, they get a bonus of 2 for things they will do that use Strength. So, I am trying to figure out how to make it so that when the Ability Score is determined, it will AUTOMATICALLY put in the Ability Modifier into it's respective spot depending on what the Ability Score is. 

 

I have attached an image in hope that it helps explain what I need better.

TOPICS
JavaScript , PDF forms
5.3K
Translate
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 Beginner ,
Jun 09, 2021 Jun 09, 2021

Here is the closest I have gotten with Code but as you can see it's showing -5 instead of what it should show. So I just don't know what I am doing wrong.

See attached image.

Translate
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 ,
Jun 09, 2021 Jun 09, 2021

To compare values for equal values use ==, not only =.

Translate
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 Beginner ,
Jun 09, 2021 Jun 09, 2021

Thank you thank you thank you thank you.
😄

Translate
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 ,
Jun 10, 2021 Jun 10, 2021

There are other issues with your code. Post it as text and we'll help you further.

Translate
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 Beginner ,
Jun 10, 2021 Jun 10, 2021

Here is what I did that seemed to work.

Also, once done with my project, do they have a place to share the files others make that they might want to share with the community?

=-=-=-=- script below -=-=-=-=-=-=-=-

 

var AbilityScoreStrength = this.getField("AbilityScoreStrength").value;

if( AbilityScoreStrength == 1 ) event.value = nSubTotal = -5;

else if( AbilityScoreStrength == 2 ) event.value = AbilityScoreStrength = -4;

else if( AbilityScoreStrength == 3 ) event.value = AbilityScoreStrength = -4;

else if( AbilityScoreStrength == 4 ) event.value = AbilityScoreStrength = -3;

else if( AbilityScoreStrength == 5 ) event.value = AbilityScoreStrength = -3;

else if( AbilityScoreStrength == 6 ) event.value = AbilityScoreStrength = -2;

else if( AbilityScoreStrength == 7 ) event.value = AbilityScoreStrength = -2;

else if( AbilityScoreStrength == 8 ) event.value = AbilityScoreStrength = -1;

else if( AbilityScoreStrength == 9 ) event.value = AbilityScoreStrength = -1;

else if( AbilityScoreStrength == 10 ) event.value = AbilityScoreStrength = 0;

else if( AbilityScoreStrength == 11 ) event.value = AbilityScoreStrength = 0;

else if( AbilityScoreStrength == 12 ) event.value = AbilityScoreStrength = 1;

else if( AbilityScoreStrength == 13 ) event.value = AbilityScoreStrength = 1;

else if( AbilityScoreStrength == 14 ) event.value = AbilityScoreStrength = 2;

else if( AbilityScoreStrength == 15 ) event.value = AbilityScoreStrength = 2;

else if( AbilityScoreStrength == 16 ) event.value = AbilityScoreStrength = 3;

else if( AbilityScoreStrength == 17 ) event.value = AbilityScoreStrength = 3;

else if( AbilityScoreStrength == 18 ) event.value = AbilityScoreStrength = 4;

else if( AbilityScoreStrength == 19 ) event.value = AbilityScoreStrength = 4;

else if( AbilityScoreStrength == 20 ) event.value = AbilityScoreStrength = 5;

else if( AbilityScoreStrength == 21 ) event.value = AbilityScoreStrength = 5;

else if( AbilityScoreStrength == 22 ) event.value = AbilityScoreStrength = 6;

else if( AbilityScoreStrength == 23 ) event.value = AbilityScoreStrength = 6;

else if( AbilityScoreStrength == 24 ) event.value = AbilityScoreStrength = 7;

else if( AbilityScoreStrength == 25 ) event.value = AbilityScoreStrength = 7;

else event.value = 0;

Translate
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 ,
Jun 10, 2021 Jun 10, 2021

Posting it here is good enough, I think.

 

There's basically the same issue in each line. Let's take this one:

if( AbilityScoreStrength == 1 ) event.value = nSubTotal = -5;

 

What's the purpose of the last part, namely:

event.value = nSubTotal = -5;

What's nSubTotal and what is it doing there?

If you just want to assign the value "-5" to the field all you need is this:

event.value = -5;

Translate
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 Beginner ,
Jun 10, 2021 Jun 10, 2021

Yep, I tried that long ago before I learned about the == but I get a syntax error. Just in case I tried it with the new working code and still I get the Syntax Error. (image provided). 

I have to step away for a while but when I return I will definately check back.

 

Translate
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 ,
Jun 10, 2021 Jun 10, 2021

May be that there is a illegal character at the end.

Translate
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 ,
Jun 10, 2021 Jun 10, 2021

Again, if you want us to help you with your code you have to post it as text.

Translate
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 Beginner ,
Jun 10, 2021 Jun 10, 2021

here it is as a text file too

Translate
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 ,
Jun 10, 2021 Jun 10, 2021

See if this works,if it doesn't work try sharing your file with us:

var AbilityScoreStrength = this.getField("AbilityScoreStrength").value;
if( AbilityScoreStrength == 1 ) event.value = -5;
else if( AbilityScoreStrength == 2 ) event.value = -4;
else if( AbilityScoreStrength == 3 ) event.value = -4;
else if( AbilityScoreStrength == 4 ) event.value = -3;
else if( AbilityScoreStrength == 5 ) event.value = -3;
else if( AbilityScoreStrength == 6 ) event.value = -2;
else if( AbilityScoreStrength == 7 ) event.value = -2;
else if( AbilityScoreStrength == 8 ) event.value = -1;
else if( AbilityScoreStrength == 9 ) event.value = -1;
else if( AbilityScoreStrength == 10 ) event.value = 0;
else if( AbilityScoreStrength == 11 ) event.value = 0;
else if( AbilityScoreStrength == 12 ) event.value = 1;
else if( AbilityScoreStrength == 13 ) event.value = 1;
else if( AbilityScoreStrength == 14 ) event.value = 2;
else if( AbilityScoreStrength == 15 ) event.value = 2;
else if( AbilityScoreStrength == 16 ) event.value = 3;
else if( AbilityScoreStrength == 17 ) event.value = 3;
else if( AbilityScoreStrength == 18 ) event.value = 4;
else if( AbilityScoreStrength == 19 ) event.value = 4;
else if( AbilityScoreStrength == 20 ) event.value = 5;
else if( AbilityScoreStrength == 21 ) event.value = 5;
else if( AbilityScoreStrength == 22 ) event.value = 6;
else if( AbilityScoreStrength == 23 ) event.value = 6;
else if( AbilityScoreStrength == 24 ) event.value = 7;
else if( AbilityScoreStrength == 25 ) event.value = 7;
else event.value = 0;

Translate
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
New Here ,
Nov 05, 2022 Nov 05, 2022

Works great. I'm doing the same thing. Related question: It already shows negative numbers with a minus(-), how can I show positives with a plus (+)?

Translate
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 ,
Nov 06, 2022 Nov 06, 2022

If for all positive number you could use custom format script or assign plus sign to every number in your script like this:

event.value = "+"+4;

Translate
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
New Here ,
Nov 07, 2022 Nov 07, 2022

Didn't work. Not a big deal, just would be nice. If using pencil and paper, player would add the plus sign.

Translate
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 ,
Nov 07, 2022 Nov 07, 2022
LATEST

You have to change the Format option to None for it to work.

Translate
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