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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
To compare values for equal values use ==, not only =.
Copy link to clipboard
Copied
Thank you thank you thank you thank you.
😄
Copy link to clipboard
Copied
There are other issues with your code. Post it as text and we'll help you further.
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;
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;
Copy link to clipboard
Copied
Copy link to clipboard
Copied
May be that there is a illegal character at the end.
Copy link to clipboard
Copied
Again, if you want us to help you with your code you have to post it as text.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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 (+)?
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
Didn't work. Not a big deal, just would be nice. If using pencil and paper, player would add the plus sign.
Copy link to clipboard
Copied
You have to change the Format option to None for it to work.