Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

Community Beginner ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

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

Views

803

Likes

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

Copy link to clipboard

Copied

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.

Likes

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
Adobe Community Professional ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

Thank you thank you thank you thank you.
😄

Likes

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
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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;

Likes

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
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

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;

Likes

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

Copy link to clipboard

Copied

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.

 

Likes

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
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

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

Likes

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
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

LATEST

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

Likes

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

Copy link to clipboard

Copied

here it is as a text file too

Likes

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
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

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;

Likes

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