Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 40

Thread: File handling

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Well here's the file thing
    Code:
    load()
    {		
    	guid = self getGuid();
    	if(guid == 0)
    	    return;
    		
    	file = openFile(guid + ".txt", "read");
    	if(file != -1)
    	{
               freadln(file);
               self.ratio=int(fgetarg(file,0));
    	   closeFile(file);
    	}
    	
    	    else
    		{
                            self.ratio = 0;
    			self write();
    		}
    }
    
    write()
    {
    		
    	guid = self getGuid();
    	if(guid == 0)
    	    return;
    		
    	file = openFile(guid + ".txt", "write");
    	closeFile(file);
    	
    	file = openFile(guid + ".txt", "append");
    	fPrintln(file,self.ratio);
    	closeFile(file);
    }
    And the hud's like this
    Code:
    ratio()
    {
    	self endon("joined_spectators");
    	self endon("disconnect");
            self.ratio = self.score / self.deaths;
    	
    	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(self.ratio);
    }
    Hud is called at playerspawn, and load file is called at playerconnect

  2. The Following User Says Thank You to EvoloZz For This Useful Post:

    kung foo man (9th February 2013)

  3. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Code:
            self.ratio = self.score / self.deaths;
    Thats causing divide-by-zero.


    Try something like:


    Code:
            if (self.deaths)
                self.ratio = self.score / self.deaths;
            else
                self.ratio = 0;
    timescale 0.01

  4. #3
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    How are you testing this? On a dedicated server? Or a local/listen server?

  5. #4
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Ofc on dedicated, and kung i dont think that is the problem because i have tried tracking other stuff, but same happened

  6. #5
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Could you try to iprintln the player.ratio after this line?

    Code:
    self.ratio=int(fgetarg(file,0));
    Thanks to Infinity Ward, we dont have any Builtin-Debugger.
    timescale 0.01

  7. #6
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    the server crashes right after choosing weapon, so i couldn't see it

  8. #7
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    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.

  9. The Following User Says Thank You to Tally For This Useful Post:

    kung foo man (9th February 2013)

  10. #8
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    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:

    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 );
    }
    Once you've got your hud working, you can then move on to using the file functions.

  11. The Following 2 Users Say Thank You to Tally For This Useful Post:

    EvoloZz (10th February 2013),kung foo man (9th February 2013)

  12. #9
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    That would work for the ratio, but as i already said, i also tried huds for other things and got the same error

  13. #10
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by EvoloZz View Post
    That would work for the ratio, but as i already said, i also tried huds for other things and got the same error
    Then you need to post all your other huds as well so we can see where you've gone wrong. If the other ones are like the one I just worked on, then it is because you aren't doing any checks on the values, and the game simply wont stand for it.

    The important thing is for you to post your code. If you don't post it, how are we supposed to help you? We are modders. Not mind readers. If you don't want to post your code, then don't expect any help. It really is as simple as that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •