Copy link to clipboard
Copied
Hello,
I am trying to automate an RPG character sheet. I also have no programming background, so this is all scary to me!
So, I have fields called "STR", "RFL", "INT", "WIS", and "CHA". These fields would all have a number put into them.
Then I have a Dropdown list called "Attribute" and the options are "STR", "RFL", etc. I want the choice made in the Dropdown list to fill a field called "Value" with the value of the chosen field. The "Value" field currently calculates with:
event.value=this.getField("Attribute").value;
It displays whatever I'm exporting from the dropdown list, but I can't get the export to be the value of the chosen field.
For example, let's say the field value for field "RFL" is 3. When "RFL" is chosen in the dropdown list, I want the "Value" field to say 3.
Thanks
Use this as 'Custom calculation script' of "SkillBonus_1" field:
var attr = this.getField("SkillAtt_1").valueAsString;
var attrField = this.getField(attr);
if (attrField==null) var skill = 0;
else skill = attrField.valueAsString;
if(skill == 0)event.value = "";
else
event.value = Number(this.getField("SkillRating_1").value)+Number(skill);
In dropdown fields properties ⇾ options tab ⇾ check 'Commit selected value immediately'.
Here is your file with script added and dropdown options ticked for fi
...Copy link to clipboard
Copied
Use this:
var attr = this.getField("Attribute").valueAsString;
var attrField = this.getField(attr);
if (attrField==null) event.value = "";
else event.value=attrField.valueAsString;
Copy link to clipboard
Copied
Here's an example of my ignorance - where do I use this? Maybe I need to give more detail. The form will have the above Attributes, and then there will be a Skills section. The Skills section looks like this:
Skill Name | Rating | Attribute | Bonus
The Skill Name is just a text field. The "Rating" will be a number. The Attribute will be the dropdown menu where the user chooses the applicable attribute (STR, RFL, etc.) The "Bonus" will be the sum of "Rating" and the corresponding Attribute chosen in the dropdown menu. For example:
Let's say STR = 3
Skill Name | Rating | Attribute | Bonus
Athletics | 2 | STR | 5
So, I need to know 2 things:
Thanks again for helping!
Copy link to clipboard
Copied
Use script as 'Custom calculation script' of "Value" field. You don't need to add anything as export value.
You can use 'Simplified field notation (SFN)' to calculate "Bonus", just write field names in SFN like this:
Rating+Value
If you have delay in calculations check 'Field calcuation order' under ⇾ Prepare form tool ⇾ 'More' ⇾ Set field calculation order.
If you don't want to show 0 in field then as 'Validate' script of "Bonus" field use this:
if(event.value == 0)event.value = "";
Copy link to clipboard
Copied
Ok, that sort of worked. 🙂
If I set the attribute first, then add a Rating, it would do the math, but the Attribute disappeared from the dropdown.
I've started my edits of this sheet from scratch, so all I've done is rename the fields in the first Skill (SkillName_1, SkillRating_1, SkillAtt_1, SkillBonus_1) and entered the Name and Ratings. I hate to ask, but could you just make the fields work for that line and then I can do it to the rest of the lines?
Copy link to clipboard
Copied
Use this as 'Custom calculation script' of "SkillBonus_1" field:
var attr = this.getField("SkillAtt_1").valueAsString;
var attrField = this.getField(attr);
if (attrField==null) var skill = 0;
else skill = attrField.valueAsString;
if(skill == 0)event.value = "";
else
event.value = Number(this.getField("SkillRating_1").value)+Number(skill);
In dropdown fields properties ⇾ options tab ⇾ check 'Commit selected value immediately'.
Here is your file with script added and dropdown options ticked for first field:
https://drive.google.com/uc?export=download&id=1lD3XfVm19quCxYoXh4H7cocsTQAi9j7O
Copy link to clipboard
Copied
Thank you so much! Now I'll just copy and paste my way to a complete sheet, but soon I'll have to stare at it long enough for it to start making sense!