Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 40

Thread: File handling

  1. #21
    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
    I have still no clue whats wrong now. Please just update the error message instead of referencing to older ones (with the correspondending source code).
    timescale 0.01

  2. #22
    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.

  3. #23
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Okay here's just everything, all scripts, all errors, whatever you need

    _file.gsc:
    Code:
    init()
    {
        thread onPlayerConnect();
    }
    
    onPlayerConnect()
    {
        level waittill("connecting",player);
        player thread load();
    }
    
    load()
    {
    	guid = self getGuid();
    	
    	if(guid != 0)
    	{
    		file = openFile(guid + ".txt", "read");
    		if(file != -1)
    		{
    			freadln(file);
    			self.kills = int(fgetarg(file,0));
    			closeFile(file);
    		}
    		
    		else
    		{
    			self.kills = 0;
    			self write();
    		}
    	}
    
    	else if(guid == 0)
    		return;
    }
    
    write()
    {
    		
    	guid = self getGuid();
    	
    	if(guid != 0)
    	{
    		file = openFile(guid + ".txt", "write");
    		closeFile(file);
    	
    		file = openFile(guid + ".txt", "append");
    		fPrintln(file,self.kills);
    		closeFile(file);
    	}
    
    	else if(guid == 0)
    		return;
    }
    tdm.gsc:
    callback_startgametype
    Code:
    	thread maps\mp\gametypes\_file::init();
    callback_playerkilled
    Code:
    				attacker.kills++;
    				attacker maps\mp\gametypes\_file::write();
                                    attacker updatehud();
    updatehud
    Code:
    updateHud()
    {
        self.killhud setValue(self.kills);
    }
    spawnplayer
    Code:
    	self thread kills();
    hud
    Code:
    kills()
    {
    	self endon("joined_spectators");
    	self endon("disconnect");
    	
    	if(!isDefined(self.killhud))
    	{
    	       self.killhud = newClientHudElem(self);
    		self.killhud.vertAlign = "fullscreen";
    		self.killhud.horzAlign = "fullscreen";
    		self.killhud.alignX = "left";
    		self.killhud.alignY = "middle";
    		self.killhud.x = 25;
    		self.killhud.y = 474;
    		self.killhud.sort = 1; 
    		self.killhud.alpha = 1;
    		self.killhud.fontScale = 0.8;
    		self.killhud.archived = true;
    		self.killhud.label = (game["ratio"]);
    		self.killhud setValue(self.kills);
    	}
    }
    Error:
    Code:
    type undefined is not a float: (file 'maps/mp/gametypes/_tdm.gsc', line 589)
      self.killhud setValue(self.kills);
                                 *
    Well i still cant figure out whats the problem, and i have tried this all just without saving into file and it worked, but it doesnt work anymore.
    I think that the problem is because the file handle and hud arent connected to each other, so thats why hud doesnt understand what the fuck is self.kills.
    Last edited by EvoloZz; 10th February 2013 at 09:31.

  4. #24
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    self.score.

  5. #25
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Why would i use self.score? Because i need to track kills, but if i kill myself score goes -1...

  6. #26
    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
    When the huds are already working, i guess its the load-function:

    Code:
    load()
    {
    	guid = self getGuid();
    	
    	if(guid != 0)
    	{
    		file = openFile(guid + ".txt", "read");
    		if(file != -1)
    		{
    			freadln(file);
    			self.kills = int(fgetarg(file,0));
    			closeFile(file);
    		} else {
    			self.kills = 0;
    			self write();
    		}
    	}
    
    
    	if (!isDefined(self.kills))
    		std\io::print("[WARNING] self.kills not defined!");
    	else
    		std\io::print("[NOTICE] self.kills is " + self.kills);
    }

    std\io::print() is printing into the console-window, so you have all debug-messages in a nutshell.

    Looking forward what it will say.
    timescale 0.01

  7. #27
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Code:
    load()
    {
    	guid = self getGuid();
    	
    	if(guid != 0)
    	{
    		file = openFile(guid + ".txt", "read");
    		if(file != -1)
    		{
    			freadln(file);
    			self.kills = int(fgetarg(file,0));
    			closeFile(file);
    		}
    		
    		else
    		{
    			self.kills = 0;
    			self write();
    		}
    	}
    
    	else if(guid == 0)
    		return;
    1. dont do an else with the inverse of the if-statement. Its useless and cod hates you for it.
    2. you seem to be testing locally, meaning your guid is zero. This means self.kills is NEVER initialized.

  8. #28
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Who told you i am testing locally? do you really think i am that stupid? and i already said in an earlier post that its dedicated, omg

  9. #29
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Ok i tested the print() thing, and it just said self.kills is 0, after /reconnect or after spawning bots, the same error happened

  10. #30
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by EvoloZz View Post
    Ok i tested the print() thing, and it just said self.kills is 0, after /reconnect or after spawning bots, the same error happened
    Well, it's not an error, your file method is not working properly. So, self.kills will always be 0 since there is no update to the data since it isn't saving it properly.

    BTW - is an actual file being created at all? what is it's name?

Posting Permissions

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