Page 1 of 1

Failed compiling js in level1targte.js

Posted: Fri Dec 16, 2011 6:56 pm
by dragon slayer
This part of the code seems to fail when server loads up.

I looked though it i can't seem to find the error
function CalcSpellDamage( caster, ourTarg, baseDamage, spellResisted )
{
    baseDamage = RandomNumber( baseDamage / 2, baseDamage );
   
    if( spellResisted )
        baseDamage = baseDamage / 2 );
       
    var casterEval = caster.skills.evaluatingintel / 10;
    var targetResist = ourTarg.skills.magicresistance / 10;
    if( targetResist > casterEval )
        baseDamage *= ((( casterEval - targetResist ) / 200 ) + 1 );
    else
        baseDamage *= ((( casterEval - targetResist ) / 500 ) + 1 );
       
    int i = RandomNumber( 0, 4 );
    if( i <= 2 )
        baseDamage = Math.round( RandomNumber( RandomNumber( basedamage / 2, baseDamage ) / 2, baseDamage ));
    else if( i == 3 )
        baseDamage = Math.round( RandomNumber( baseDamage / 2, baseDamage );
    else //keep current damage
        baseDamage = Math.round( baseDamage );
   
    return baseDamage;
}

Posted: Sat Dec 17, 2011 1:45 am
by Xuri
Hm. Possibly because I wrote
int i = 0;
while it should have been
var i = 0;

Posted: Sat Dec 17, 2011 2:49 am
by dragon slayer
Oh lol i didnt notice all that

Posted: Tue Dec 20, 2011 5:47 am
by Xuri
The actual real culprit was the extra parenthesis at the end of the second line here:

Code: Select all

 if( spellResisted ) 
       baseDamage = baseDamage / 2[color=red] )[/color];
That parenthesis should not have been there :P

...while there _should_ have been one at the end of the second line here:

Code: Select all

	else if( i == 3 )
		baseDamage = Math.round( RandomNumber( baseDamage / 2, baseDamage )[color=red])[/color];

Posted: Tue Dec 20, 2011 7:09 am
by dragon slayer
i did notice that one was missing when i did the var fix

Posted: Tue Dec 20, 2011 4:12 pm
by John
For some reason I had it in my head that when you do:

if( blah )
{
blah
}

In Javascript do you not need to use brackets in code like C++?

Posted: Tue Dec 20, 2011 7:29 pm
by Xuri
If there is only one follow-up line it's not required to use the brackets in neither Javascript nor C++. Some people swear to using it always and forever though. Depends on what coding style you prefer.

Personally I drop the brackets when there's only one line after an if or else. So:

Code: Select all

if( blah )
	blahblah = blergh;
else if( bluh = green )
{
	bleh = green;
	bluh = blue;
}
else
	Nii!;

Re: Failed compiling js in level1targte.js

Posted: Mon Mar 19, 2012 3:19 pm
by Xuri
The fix for this is now available in UOX3 0.99, and on the CVS.