in need of a simple highscore.

Posted By: Realspawn

in need of a simple highscore. - 11/15/12 14:08

Hello for my latest little project i am trying to create a
working highscore (No need for name imput)

I use this for now.

Code:
function highscore()
{
	if (score_count >= hscore_count )
	set(highscore_pan,SHOW);
}



basicly i have two var. one is the score_count the other is hscore count wich is set on a certain number. No when highscore is broken i need the hscore_count to go the same as the score from here but also saves this new highscore at game end.

Any ideas or examples you could point me to laugh
Posted By: Kartoffel

Re: in need of a simple highscore. - 11/15/12 14:16

As far as I understand you you want to save and load the highscore, is this right?
Posted By: Kartoffel

Re: in need of a simple highscore. - 11/15/12 14:28

Well if I understood you right here's a small - not testet - example:

Code:
#define HIGH_SCORE_SAVE_FILE "hs.score"

TEXT* input_file = { strings = 1; } // used to load saved information, only one string needed

void load_highscore()
{
	txt_load(input_file, HIGH_SCORE_SAVE_FILE);
		wait(1); // wait one frame to load the text file - important!
	
	hscore_count = str_to_float( (input_file.pstring)[0] ); // (<text>.pstring) [ line, beginning with 0! ] -> convert to float
}

void save_highscore()
{
	var file_handle = file_open_write(HIGH_SCORE_SAVE_FILE);
	wait(1); // wait to open the file?? - not sure if this is needed
	
	file_str_write(file_handle, str_for_float(NULL, (double)hscore_count)); // convert the highscore to a string -> write into file
	file_close(file_handle);
}

Posted By: Realspawn

Re: in need of a simple highscore. - 11/15/12 14:38

that's indeed what i ment. I will give this a shot laugh
so do i need to create a txt file first and put it in my work directory ?
Posted By: Kartoffel

Re: in need of a simple highscore. - 11/15/12 14:49

Well actually no wink
The file gets written automatically if you call save_highscore();
and if it already exists it gets overwritten, so theres no need to delete the file before writing a new highscore over it.

I defined the file name in my example with:
#define HIGH_SCORE_SAVE_FILE "hs.score"

EDIT: thats not very secure... but with an easy encryption it should be secure enough smile
EDIT#2: if you need some help with en- and decrypting the highscore let me know wink
© 2024 lite-C Forums