Function Help

First off, I want to say kudos to you for this amazing product, I've been looking for something of this nature for quite a while. However, as I do not know javascript it has been a learning experience (literally!) in designing the sheet I have in mind. As such, I have run across a problem with a certain function, no doubt related to my inexperience with javascript. I either do not know where to look, or am just unable to find what I need.

I want to write a function which references to see whether or not a checkbox is checked, and based upon whether it is checked or not, to enter one of 2 different values from adding other fields into the one containing the function. Basically, the function, when entered into field 1, will reference the checkbox, and then add Field A + B if it is, or Field A + C if it is not, and enter that into Field 1. [I'm trying to have a box set up for Weapon Finesse, that a player can click to toggle between Str or Dex bonus].

I've created a rough function, which returns no error, but when I run the sheet, it just fills the field with the text of the entire function. I'm sure it's something foolish of which I am not aware. Here's what I have:

function AttackTotal()
{
if (Test.Checkbox.checked == true) {
return DexterityMod.value + BAB.value;
}
else {
return StrengthMod.value + BAB.value;
}
}

If needed, here is the csd file.

Comments

  • If anyone else is curious, I found a solution! It's probably not the best, or prettiest, but all I know is it works!

    function AttackTotal( n)
    {
    if (Checkbox.checked)
    {
    return Math.floor( n + Field1.Value);
    }
    else
    {
    return Math.floor ( n + Field2.Value);
    }
    }

Leave a Comment