• The VOIDRUNNER'S CODEX is coming! Explore new worlds, fight oppressive empires, fend off fearsome aliens, and wield deadly psionics with this comprehensive boxed set expansion for 5E and A5E!

Anyone in here know Acroscript, or more accurately Adobe Acrobat's version of Javascript?


log in or register to remove this ad


Alan Shutko

Explorer
I've updated my sample PDF. It now has two document-level javascripts. To edit those, go into Form Edit mode, click Other Tasks, then select Document Javascripts.

The first script sets up a global variable with the stat bonuses:

Code:
global.racialStatMods = {};

global.racialStatMods['Elf'] = {};
global.racialStatMods['Elf']['Strength'] = -1;
global.racialStatMods['Elf']['Agility'] = 3;
global.racialStatMods['Elf']['Reasoning'] = 2;
global.racialStatMods['Elf']['Constitution'] = 0;

and so forth.

The second script defines a lookup function which will return the bonus for a given race and stat:

Code:
function racialMod(race, class)
{
    return global.racialStatMods[race][class];
}

The javascript calculation for the field then can just call the function:
Code:
event.value = racialMod(this.getField("Race").value, this.getField("Stat").value)

Copy and paste the JS from the PDF, since it seemed when you copied from the forum here it lost the newlines.
 

Madmaxneo

Explorer
That looks good. But, I can't seem to find the global scripts in the document. I read something about them in the little scripting guide but it was just a paragraph. I could attempt to copy them from here again, but, based on not knowing where to find them I wouldn't know where to place them. I don't want to place them in another document as I plan on making this available to anyone who wants the character sheet for download.

Bruce
 

Alan Shutko

Explorer
When you open my document, click on Tools, Forms, then Edit:

Screenshot 2014-08-30 21.06.08.png

Then, click on Other Tasks, Document Javascripts

Screenshot 2014-08-30 21.06.20.png

Then you should see a window like this pop up:

Screenshot 2014-08-30 21.09.42.png
 

Madmaxneo

Explorer
I was editing my post with a possible different course to take. But you apparently was watching the thread and got in there and added your post then I had to cancel mine....lol. This is the example I was given and i think it might work better, for one because all the stats are fixed and are not in a pull down list.
the value of each object property could be an array, something like: var oT2 = {
"Dwarf" : [3, 0, 0, 2],
"Human" : [1, 1, 2, 1],
"Elf" : [-1, 3, 2, 0],

"Gryx" : [3, 0, 1, 2]
}

To get the second (Agility) item in the array for the "Human" array, the code would look like:

var val = oT2["Human"][1];

To get the last item (Constitution)in the "Dwarf" array, you could do this:

var val = oT2["Dwarf"][2];

The problem is the race has to be pulled from another field (that is a dropdown list) that will be a variable where the race (Human and Dwarf above) is in the "var val" section of the script, then how to put that into script that will work together maybe like your global variables.

Bruce
 

Madmaxneo

Explorer
Oh, I forgot one thing.... In the first code for the bonus associated with the number of ranks. How would I add in one more bonus number? If there are "0" (zero) or no ranks in the field then the bonus is -25.

I figured it out! I added another "else if" statement and it worked!!!

"Happy dance"....lol.

Bruce
 
Last edited:

Madmaxneo

Explorer
Some errors.
First I am getting this security error whenever I close the global script in the document Javascripts:
NotAllowedError: Security settings prevent access to this property or method.Global.racialStatMods:1:Document-Level:RacialStatMods
I couldn't find any security settings to change to fix this.

Now for the code errors. I'm trying it your way but when I select the race I am getting the error:
racialMod is not defined1:AcroForm:St.2:Calculate
ReferenceError: racialMod is not defined
1:AcroForm:St.2:Calculate
This is a sample of the code I am using under RacialStatMods (I dropped the "init" from your example do I need that?) in the document Javascripts:
Code:
global.racialStatMods = {};

global.racialStatMods['Dwarf'] = {};
global.racialStatMods['Dwarf']['St'] = -1;
global.racialStatMods['Dwarf']['Co'] = 3;
And here is the RacialMod under document Javascripts:
Code:
function racialMod(Race, class){
    return global.racialStatMods[Race][class];
}

In the meantime I will try adding the "init" back into the title of the global script to see if that works.

EDIT: I am using this script to pull the "St " value for the strength bonus based on race:
Code:
event.value = racialMod(this.getField("Race").value, (St).value)

Bruce
 
Last edited:

Madmaxneo

Explorer
Ignore all that above. I kind of got it fixed. I somehow fixed the security error....lol.

The problem is in that script to pull the "Strength" you use this formula:
event.value = racialMod(this.getField("Race").value, this.getField("Stat").value)

But in mine I don't have a field named stat and in fact the base sheet is converted from an excel sheet so where the stats are (i.e. Strength, Constitution, etc) there are no fields but there is the text from the excel spreadsheet with the stats in it. So. I need to change that formula above to where it doesn't look for the this.getField("Stat").value but instead looks up the "St" in the global script I put in. So how do I do that?

Bruce
 

Madmaxneo

Explorer
Ok, for now I concede because I am trying to get this thing finished and hopefully real soon. I ended up creating the fields for now (there was only 13).
I need help in combining that script
Code:
event.value = racialMod(this.getField("Race").value, this.getField("Stat10").value)
with a basic
Code:
sum of Rank Bns 1.15, Spec Bns 1.15, Stat Bns 1.15
Where Rank Bns 1.15 (and the other two) is one of the fields I need to add to get the total bonus. Right now I have that racialMod script in the special mods field and I need that to be clear so the player can add any other special bonuses that come up during their adventuring career.

I also need to do a script that will figure in the bonus for the stats. The numbers follow no special mathematical pattern so it would have to be something like:
Code:
(5, .1), (15, .1), (50, 2), (75, 5), (90, 7)
Where the first number is the stat and the second number is the bonus derived from the stat.

Bruce
 

Remove ads

Top