cytec123187@gmail.com writes:
[color=blue]
> I am not sure I understand what you are saying. Please note that this
> is within an Acrobat document.[/color]
(I don't know which features of modern Javascript the scripting engine
of pdf-viewers implement, but the functionality should be available,
even though some shorthand notations might not be.)
[color=blue]
> I thought about using logic statements to arrange this, but I don't
> know how. For example...[/color]
The point here is that you have a table of data to implement.
Implementing that with switches and if statments is overkill, and you
should instead make a look-up table in your code and use generic code
to look up the values.
[color=blue]
> var a = this.getField("Class");
> var b = this.getField("Character_Level");
> switch(a.value)
> {
> case "Fringer":
> if (b.value == 1)
> event.value = "+2";[/color]
If you just had a table, you could look up the value as:
var className = a.value;
var level = b.value;
event.value = lookupTable[className][level - 1];
This could be the table Thomas Lahn suggested:
var lookupTable = {
Fringer: [2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12, (etc)],
Noble: [0,0,1,1,1,2,2,2,3,3, (etc)],
...etc.
};
(or, if object and/or array literal notation is not available,
var lookuptTable = new Object();
lookupTable["Fringer"] = new Array(2,3,3,4,4,5,5, ...);
lookupTable["Noble"] = new Array(0,0,1,1,1,2,2,2,...);
...
)
[color=blue]
> ...but I don't want an if/else because I am limited to only two option
> when there are 30 options I need to include. Is there a way to open a
> switch within a switch, something like this...
>
> var a = this.getField("Class");
> var b = this.getField("Character_Level");
> switch(a.value)
> {
> case "Fringer":
> switch(b.value)
> {
> case 1:
> event.value = "+2";[/color]
Have you tried it?
It should work. It's still *far* from the simplest solution.
[color=blue]
> I don't know how to do advanced scripting. I am an unskilled novice at
> best. The following is a portion of the data I need entered. Maybe it
> will help in some way...[/color]
Another solution suggests itself, when you notice the regularity of
the numbers. You can compute the bonus value from the level through a
mathematical formula, and implement that as a function.
function goodSave(level) {
return 2 + Math.floor(level / 2);
}
function badSave(level) {
return Math.floor(level / 3);
}
Then you can make a look-up table from class name to bonus *function*:
var lookupTable = {
Fringer : goodSave,
Noble : badSave,
... etc...
}
and then look up the function and use it:
var className = this.getField("Class");
var level = Number(this.getField("Character_Level"));
event.value = lookupTable[className](level);
Again, I have no experience with Acrobat, or its Javascript support,
so some of this might not work directly.
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'