high score carryover

Posted By: JazzDude

high score carryover - 09/29/12 16:43

How can I use the saved high score, which is in a text file, in an equation in a subsequent level which is a separate game.
Posted By: Superku

Re: high score carryover - 09/29/12 17:10

Just read the text file again with the file_open_read/ file... instructions.
Posted By: JazzDude

Re: high score carryover - 09/30/12 04:53

Thanks, Superku

I tried this:

Code:
function points_startup()
{
var filehandle;
filehandle = file_open_read("highscore.txt");
if (filehandle)&&(level == 2) 
	{
	   file_str_read(filehandle, name_str);
	   points = file_var_read(filehandle);
	}
else 
{
	str_cpy(name_str, "None");
	points = 0;
}
             
}


But I'm doing something wrong. When level 2 starts the points variable reads 0 instead of the saved high score.

Just had a thought. Maybe I should save the high score as a .dat file instead of a .txt
Posted By: lemming

Re: high score carryover - 09/30/12 08:34

The extension is irrelevant. The problem is you don't close the file after reading it. http://www.conitec.net/beta/afile_close.htm
So when you start the function a secound time in level 2 the file is still open.
If you don't need access to a file anymore always close it.
Posted By: JazzDude

Re: high score carryover - 09/30/12 18:42

Thanks. It's working now.

Yes, I found the .dat extension only changes the saved number with decimals.
© 2024 lite-C Forums