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

Madmaxneo

Explorer
I am in need of some scripting help. I am trying to program a character sheet for a game system into a PDF form so that all the calculations are automatic (well most of them).
I need help with creating an array and objects to simulate tables in the PDF. Since Adobe Acrobat uses an "enhanced" version of javascript it isn't quite the same. But if you know javascript you still might be able to help. Please let me know.

Bruce
 

log in or register to remove this ad

Alan Shutko

Explorer
Could you spell out an example of what you want to do? I haven't really tried javascript in Acrobat, but I have it, and I'm a web developer, so I'd be willing to spend an hour or so figuring it out. (For a similar reason: I'd like an auto calculating RCD&D sheet.)
 

Madmaxneo

Explorer
Sweet! I really hope you can help me. First, all this will go into the "Custom Calculation Script" in the calculate tab under the properties menu when in edit mode.
Ok, first I am attempting to simulate a 2 column table where the first column is the rank for a skill and the second column is the bonus associated with that skill.
In this game the first 10 ranks in a skill give a +5 per rank, the next 10 ranks give a +2 per rank and any ranks over 20 give an additional +1 per rank.
The script needs to pull the number for column 1 from another field (I will use Ranks.1) in the PDF form and output the corresponding result for that rank number. Here's a varied example.
15
1152
2272
3080
<tbody> </tbody>
I have been given an example to go by but I have no idea what I am looking at and it is incomplete.
It is:
An object is a good way to implement this. For the first, the object would look like this: var oT1 = { "5" : 0.1, "50" : 2, "75" : 6, "100" : 12}
To get the value associated with the 100 property, the code would look something like:
var val = oT1["100"];
The variable "val" would then contain the number 12.
As you can see it doesn't show how to get the variable rank number where the "100" is in the oT1 part.

The second would be an array to simulate a table (at least that is what I have been told it would be) that has multiple rows and columns. Where column one would be all the races and Row one would be the 8 stats. The cross reference would be the bonus to the stat from Row 1 and the Race from column 1. Here is an example (these numbers aren't the actual game numbers):

StrengthAgilityReasoningConstitution
Elf-1+3+20
Human+1+1+2+1
Dwarf+300+2
Gryx+30+1+2
<tbody> </tbody>
I have an example for this as well but lets focus on the first one for now.
Also, as you may well know Acroscript is based on Javascript but it has some different features and settings.
Bruce
 

delericho

Legend
I've done a little bit, for auto-calculating character sheets, but I certainly don't pretend to be an expert!

In particular, I've never done anything with arrays. Generally, for what you're suggesting, I'd set up a hidden field StrMod (or similar) that reads the value of the Race field and sets the value accordingly (probably just using an if statement). Similarly for AglMod, ReasonMod, and ConMod.

I'm not sure it helps much, but here's what I did to calculate level on a SWSE character sheet:

var xpFld = this.getField("XP.Total")
var lvWorking = 1
var a = 0
var mult = 1000

if(xpFld.value == "")
{
a = 0
}
else
{
a = xpFld.value
}

while(a >= (lvWorking * mult))
{
a = a - (lvWorking * mult)
lvWorking = lvWorking +1
}

event.value = lvWorking


As you can hopefully see, it first reads the value from the XP.Total field into a local variable, and then uses that in its calculations. Though I'm sure someone who actually knows what they're doing will be shaking his head in disgust at this... :)
 

Madmaxneo

Explorer
I've done a little bit, for auto-calculating character sheets, but I certainly don't pretend to be an expert!

In particular, I've never done anything with arrays. Generally, for what you're suggesting, I'd set up a hidden field StrMod (or similar) that reads the value of the Race field and sets the value accordingly (probably just using an if statement). Similarly for AglMod, ReasonMod, and ConMod.

I'm not sure it helps much, but here's what I did to calculate level on a SWSE character sheet:

"See Code in the previous post"

As you can hopefully see, it first reads the value from the XP.Total field into a local variable, and then uses that in its calculations. Though I'm sure someone who actually knows what they're doing will be shaking his head in disgust at this... :)

That looks very similar to what I did in Maptools for experience I was going to post it here but it's a little long. It has code in it that automatically changes your level when you get enough exp and has an exp bar you can put on your character to show how close you are to next level. I had some help in developing it from one of the top programmers on the maptools forums.
Unfortunately Maptools (which is also based off of Javascript) is significantly different than Acroscript.
Hopefully Alan Shutko is still wiling to help me with this. I hope I didn't discourage him with what I posted...lol.

Bruce
 

Alan Shutko

Explorer
I've put together a quick mockup to help us discuss things.

I would not use a dictionary for this. Here's what I would do:

Code:
var rank = this.getField("RankRow1").value
var value = 0

if (rank > 20) {
   value = 10*5 + 10*2 + (rank - 20)
} else if (rank > 10) {
  value = 10*5 + (rank - 20)*2
} else {
  value = rank * 5
}

event.value = value

If you're putting the same calculation in multiple fields, we can change this to automatically calculate what field to get the rank from. Then you can put the same script in each place. I'll take a look at that next.
 




Madmaxneo

Explorer
Which version of acrobat do you have? I ran this in Acrobat XI. It may need tweaking for earlier versions. Let me know what you have and I can install it.
I have acrobat XI. I use the Adobe cloud services which always updates to the latest.
Here is the exact script I used:
Code:
var rank = this.getField("Ranks1").value var value = 0 if (rank > 20) { value = 10*5 + 10*2 + (rank - 20) } else if (rank > 10) { value = 10*5 + (rank - 20)*2 } else { value = rank * 5 } event.value = value
As you can se the field I am getting the code from is named Ranks1
Bruce
 
Last edited:

Remove ads

Top