Copy link to clipboard
Copied
Hello i have a two dropdown fields, two text fields with values, and a text field with a custom calculation script.
I have this in the text field:
var class1 = this.getField("Class1");
var class2 = this.getField("Class2");
var level1 = this.getField("Level1");
var level2 = this.getField("Level2");
if ((class1.value==="Bard")||(class1.value==="Cleric")||(class1.value==="Druid")||(class1.value==="Sorcerer")||(class1.value==="Wizard"))
{
var a = level1;
if ((class2.value==="Bard")||(class2.value==="Cleric")||(class2.value==="Druid")||(class2.value==="Sorcerer")||(class2.value==="Wizard")) {var b = level2;}
else if ((class2.value==="Paladin")||(class2.value==="Ranger")) {var b = Math.floor(level2 / 2);}
else if (class2.value==="Artificer") {var b = Math.ceil(level2 / 2);}
else if ((class2.value==="Fighter")||(class2.value==="Rogue")) {var b = Math.floor(level2 / 3);}
else{var b = 0;}
var spellCasterLevel = a + b;
event.value = spellCasterLevel;
}
else if ((class1.value==="Paladin")||(class1.value==="Ranger"))
{
var a = Math.floor(level1 / 2);
if ((class2.value==="Bard")||(class2.value==="Cleric")||(class2.value==="Druid")||(class2.value==="Sorcerer")||(class2.value==="Wizard")) {var b = level2;}
else if ((class2.value==="Paladin")||(class2.value==="Ranger")) {var b = Math.floor(level2 / 2);}
else if (class2.value==="Artificer") {var b = Math.ceil(level2 / 2);}
else if ((class2.value==="Fighter")||(class2.value==="Rogue")) {var b = Math.floor(level2 / 3);}
else{var b = 0;}
var spellCasterLevel = a + b;
event.value = spellCasterLevel;
}
else if (class1.value==="Artificer")
{
var a = Math.ceil(level1 / 2);
if ((class2.value==="Bard")||(class2.value==="Cleric")||(class2.value==="Druid")||(class2.value==="Sorcerer")||(class2.value==="Wizard")) {var b = level2;}
else if ((class2.value==="Paladin")||(class2.value==="Ranger")) {var b = Math.floor(level2 / 2);}
else if (class2.value==="Artificer") {var b = Math.ceil(level2 / 2);}
else if ((class2.value==="Fighter")||(class2.value==="Rogue")) {var b = Math.floor(level2 / 3);}
else {var b = 0;}
var spellCasterLevel = a + b;
event.value = spellCasterLevel;
}
else if ((class1.value==="Fighter")||(class1.value==="Rogue"))
{
var a = Math.floor(level1 / 3);
if ((class2.value==="Bard")||(class2.value==="Cleric")||(class2.value==="Druid")||(class2.value==="Sorcerer")||(class2.value==="Wizard")) {var b = level2;}
else if ((class2.value==="Paladin")||(class2.value==="Ranger")) {var b = Math.floor(level2 / 2);}
else if (class2.value==="Artificer") {var b = Math.ceil(level2 / 2);}
else if ((class2.value==="Fighter")||(class2.value==="Rogue")) {var b = Math.floor(level2 / 3);}
else {var b = 0;}
var spellCasterLevel = a + b;
event.value = spellCasterLevel;
}
else
{
var spellCasterLevel = 0;
event.value = spellCasterLevel;
}
But when I change the value of the first dropdown field (Class1) I get either "NaN", "[object Field]0", or "0". The last one is only if I leave the field empty.
What is going wrong?
level1 and level2 are field objects.
To use the values of the fields you must use e.g. level1.value
Copy link to clipboard
Copied
level1 and level2 are field objects.
To use the values of the fields you must use e.g. level1.value
Copy link to clipboard
Copied
No, "level1" and "level2" are variables defined at the start of the code. "Level1" and "Level2" are the fields.
And since I havn't implemented the levels in the code yet it can't be a issue. The only fields that are used in the code are "Class1" and "Class2" and the variables "class1" and "class2".
Copy link to clipboard
Copied
And the way I'm defining the variables "class1", "class2", "level1", and "level2" is used in many other places in the document and it works perfectly.
Copy link to clipboard
Copied
Sorry I'm tired... I am using the "level1" and "level2" variables in the code 😛 But I still don't think that they are the problem since they are working in other places.
Copy link to clipboard
Copied
No, it's not. You're using them incorrectly. For example, here:
Math.floor(level2 / 2);
It should be:
Math.floor(level2.value / 2);