How are you testing this? On a dedicated server? Or a local/listen server?
Printable View
How are you testing this? On a dedicated server? Or a local/listen server?
Thats causing divide-by-zero.Code:self.ratio = self.score / self.deaths;
Try something like:
Code:if (self.deaths)
self.ratio = self.score / self.deaths;
else
self.ratio = 0;
Ofc on dedicated, and kung i dont think that is the problem because i have tried tracking other stuff, but same happened
Could you try to iprintln the player.ratio after this line?
Thanks to Infinity Ward, we dont have any Builtin-Debugger. :rolleyes:Code:self.ratio=int(fgetarg(file,0));
the server crashes right after choosing weapon, so i couldn't see it
If I were doing this, I would first get the hud working independently of the file function method. Then, once it's working correctly without any errors, I would introduce the file function method.
Doing it that way will narrow the problems down. You will then be able to isolate any errors without having to determine what effect the other method is having on things.
I'm saying this because I am pretty sure the hud code is not correct and is causing runtime errors. Sort that out first. Then move on to the file function method.
Ok, as I suspected, the ratio hud was a mess, so I wrote a test script in order to see what was crashing the server. And it was that you can't divide 0 by a 0. Below is the test script I wrote. I have no idea exactly what you are trying to do, so I just updated the value every frame. Obviously, you change that to suit your purposes. But the method is sound - don't update the value while self.ratio is zero (otherwise it throws an error) and only apply a division once both self.score and self.deaths are defined.
This is what I ended up with:
Once you've got your hud working, you can then move on to using the file functions.Code:init()
{
level thread onPlayerConnect();
}
onPlayerConnect()
{
for( ;; )
{
level waittill( "connected", player );
player thread onPlayerSpawned();
player thread onPlayerKilled();
}
}
onPlayerSpawned()
{
self endon( "disconnect" );
for( ;; )
{
self waittill( "spawned_player" );
self thread ratio();
}
}
onPlayerKilled()
{
self endon( "disconnect" );
for( ;; )
{
self waittill( "killed_player" );
if( isDefined( self.ratiohud ) )
self.ratiohud destroy();
}
}
ratio()
{
self endon( "killed_player" );
self endon( "disconnect" );
if( isDefined( self.ratiohud ) ) self.ratiohud destroy();
if( !isDefined( self.ratiohud ) )
{
self.ratiohud = newClientHudElem( self );
self.ratiohud.vertAlign = "fullscreen";
self.ratiohud.horzAlign = "fullscreen";
self.ratiohud.alignX = "left";
self.ratiohud.alignY = "middle";
self.ratiohud.x = 25;
self.ratiohud.y = 474;
self.ratiohud.sort = 1;
self.ratiohud.alpha = 1;
self.ratiohud.fontScale = 0.8;
self.ratiohud.archived = true;
self.ratiohud.label = (game["ratio"]);
self.ratiohud setValue( 0 );
}
for( ;; )
{
wait( 0.05 );
self.ratio = self getRatio();
if( !isDefined( self.ratio ) )
continue;
else
{
if( isDefined( self.ratiohud ) )
self.ratiohud setValue( self.ratio );
}
}
}
getRatio()
{
value = undefined;
if( !self.score && !self.deaths )
value = 0;
else if( self.score && !self.deaths )
value = self.score;
else if( self.score && self.deaths )
value = ( self.score / self.deaths );
return( value );
}
That would work for the ratio, but as i already said, i also tried huds for other things and got the same error
Same expect the value was different of course