#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Java Errors

edited September 2011
I'm designing a sheet for Call of Cthulhu and I'm leaping in feet first into the world of Java. I know Basic, VBasic and FORTRAN, but not Java, so, my problem might be simple syntax.

Anyway, I had three fields that would contain the value of another field * 5. So, "Idea" is INT * 5, "Luck" is POW * 5 and "Know" is EDU * 5. For example, in "Idea" the Source has, "txtINT.value * 5" (no quotes, of course).

These all worked just fine until I tried to enter a function for Damage Bonus. A character's Damage Bonus is based upon the addition of its STR and SIZ. The sum is looked up on a chart and a modifier is determined. For lower sums, I used an if/then process and for higher ones, I needed to divide the total by 16 and then add additional d6 according to the answer. At the end, I'll provide the code I wrote.

So, I wrote the code, put it in the Script tab and it failed. OK, fine, except that, for some reason, the other calculations - Idea, Luck and Know - stopped working. I remove the code, those calculations work again. So, not only is my code not working, it also causes everything else to fail.

If someone could take a gander at my code and let me know what I may have done wrong, I'd appreciate it.

Here's what I wrote;
```function fDamageBonus()
{
int iSTRnSIZ = 0;
int iDamDice = 0;
if (iSTRnSIZ &lt;= 12) {
return txtDamageBonus.text = '-1d6';
} else if (iSTRnSIZ &lt;= 16) {
return txtDamageBonus.text = '-1d4';
} else if (iSTRnSIZ &lt;= 24) {
return txtDamageBonus.text = '0';
} else if (iSTRnSIZ &lt;= 32) {
return txtDamageBonus.text = '+1d4';
} else if (iSTRnSIZ &lt;= 40) {
return txtDamageBonus.text = '+1d6';
} else if (iSTRnSIZ &lt;= 56) {
return txtDamageBonus.text = '+2d6';
} else if (iSTRnSIZ &lt;= 72) {
return txtDamageBonus.text = '+3d6';
} else if (iSTRnSIZ &lt;= 88) {
return txtDamageBonus.text = '+4d6';
} else if (iSTRnSIZ &gt; 88) {
iDamDice = int ((iSTRnSIZ - 88) / 16) + 5;
return txtDamageBonus.text = '+' + iDamDice + 'd6';
}
}
```

It fails no matter if I put fDamageBonus() as the Source of the Damage Bonus field or not. As long as this code exists in Script tab, nothing works.

A thought hit me and I removed the "txtDamageBonus.text = " from each return command (adding parentheses around "'+' + iDamDice + 'd6'", but no difference.

Any ideas?

• The Character Sheet Designer uses JavaScript, not Java. Java and JavaScript are two different, unrelated languages (with unfortunately similar names). It looks like you're declaring variables with a type ("int iSTRnSIZ = 0;"), which is what you'd do in Java, but not in JavaScript.
• Ah, well, that'll make a difference.

OK, I've changed the variable declarations to "var" and now, it runs with no errors, but the Damage Bonus field won't update when I enter the stats for STR and SIZ.

I'll have to go over the help file to see if there are events that must be anticipated - although, the "Idea," "Luck" and "Know" fields update without any.
• Scratch that. I just noticed that my code doesn't initialize the iSTRnSIZ variable with the values of txtSTR or txtSIZ.

Now, it works!

Eureka! Or, is that Mereka?

Ha! I slay me...