Copy link to clipboard
Copied
Hello, I have created a character sheet for a game and I am stuck trying to translate drop down menu choices into numerical values to work with. The point is that a character is supposed to gain different bonuses according to the race chosen (as shown in the human/elf example below). Now I have the dropdown menu "Races" and I would like to have all the "racialmodXXX" added to the corresponding text fields (for example the "Agilitytotal" text field should be computed by adding the entered value in the "Agility" text field + "racialmodagi".)
This is what I have entered into the validation box of the "Races" dropdown menu:
var racetype = this.getField('Races');
var racialmodbody = '0';
var racialmodagi = '0';
var racialmodreac = '0';
var racialmodstr = '0';
var racialmodwill = '0';
var racialmodlog = '0';
var racialmodint = '0';
var racialmodcha = '0';
var racialmodedge = '0';
var racialmodmag = '0';
if (racetype.value == 'Human')
{
racialmodbody.value='0';
racialmodagi.value='0';
racialmodreac.value='0';
racialmodstr.value='0';
racialmodwill.value='0';
racialmodlog.value='0';
racialmodint.value='0';
racialmodcha.value='0';
racialmodedge.value='1';
racialmodmag.value='0';
}
if (racetype.value == 'Elf')
{
racialmodbody.value='0';
racialmodagi.value='1';
racialmodreac.value='0';
racialmodstr.value='0';
racialmodwill.value='0';
racialmodlog.value='0';
racialmodint.value='0';
racialmodcha.value='2';
racialmodedge.value='0';
racialmodmag.value='0';
}
The text field "Agilitytotal" is supposed to report "(Agility) + (racialmodagi)" by calculation but it doesn't. Once I remove (racialmodagi) from the calculation window, it works properly.
Sorry for the wall of text but maybe some of you have an idea how to solve this.
Thanks a lot in advance!
Copy link to clipboard
Copied
Drop the quotes around all the numbers in your code.
Copy link to clipboard
Copied
Thanks. I have tried your suggestion but it didn't solve the problem.
Copy link to clipboard
Copied
Post your full code, please. Also, why did you place it as a validation script, and not a calculation one?
Copy link to clipboard
Copied
Ah, I think I see now what you tried to do... It should work, but you should replace all the instances of:
racetype.value
With:
event.value
Also, make sure to tick the option to commit the selected value immediately, under the drop-down's Properties, Options tab.
Copy link to clipboard
Copied
Thanks for your reply. I have tried all your suggestions without success.
About your questions:
Why the validation window?
Since the dropdown menu does not really calculate and only serves as a setup for calculation on other fields I thought the calculation should be put into those other fields and I didn't see any other option to put the code in except for validation.
What I was trying to do?
1. Create text fields for 8 attributes where users enter numbers.
2. Create drop down menu and enter races.
3. Translate each race into numerical values and write these values into hidden variables.
4. Behind the 8 attribute text fields there are 8 attributetotal text fields. These 8 fields should show the combined result of the data entered in 1. + the data from the hidden variable (according to chosen race) for each field
Calculation works fine between all text fields.
Copy link to clipboard
Copied
Can you post your current code, or (better yet) share the file (via Dropbox, Google Drive, Adobe Cloud, etc.)?
Copy link to clipboard
Copied
This looks like a situation to use the JavaScript prototype.
Copy link to clipboard
Copied
Read this article:
https://acrobatusers.com/tutorials/change_another_field
It'll show you how to best organize your data, and the correct way to set other values.
And since your interested in games, here is an example as PDF as a game platform, look at the Swat The Fly game on this page:
Free Sample PDF Files with scripts
Copy link to clipboard
Copied
@Thom Thanks a lot! Actually I was looking to find example PDFs for me to learn. I will definately check these out.
I was able to change data with simple methods but the problem I seem to have with the dropdownmenu is that I need each "choice" to influence multiple variables accross the PDF (instead of just one).
@try67 Thanks for your effort. Unfortunately I can't distribute the PDFs as they contain copyrighted material.
@gkaiseril I'm too inexperienced to actually have an opinion on that.