[FIXED] Failed compiling js in level1targte.js

Here we stuff all the bugs we've managed to squash/squish/squelch.
Locked
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Failed compiling js in level1targte.js

Post 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;
}
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Hm. Possibly because I wrote
int i = 0;
while it should have been
var i = 0;
-= Ho Eyo He Hum =-
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

Oh lol i didnt notice all that
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post 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];
-= Ho Eyo He Hum =-
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

i did notice that one was missing when i did the var fix
John
UOX3 Neophyte
Posts: 32
Joined: Thu Sep 15, 2011 7:41 am
Location: Inside Tom's Brain
Has thanked: 0
Been thanked: 0

Post 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++?
Last edited by John on Thu Jan 09, 2014 6:15 am, edited 1 time in total.
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post 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!;
-= Ho Eyo He Hum =-
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

The fix for this is now available in UOX3 0.99, and on the CVS.
-= Ho Eyo He Hum =-
Locked