GameMaker Highscore

T

tobii

Guest
Hey everyone,

so i am trying to add a highscore list to my end room (r_score) where the player can see al prev highscore and choose to start a new game or quit now the start and quit button work but i can't seem to find a way to add the highscores, it showes only one score all the time as well as in my save.ini file, now my question would be how can i make it put in more highscore so that i can print out that list on my screen? and how do i print the list on my screen? since it wont show any text here is my code

Code:
obj_score (just a UI thing for the screen)

//create
score = 0;

//draw GUI

draw_highscore(224,96,404,150);
//Parametres are for the position

draw_text(640/2-100, 340-32, string_hash_to_newline("Press C to clear high score"));


then we have the player obj

//create
alarm[0] = 200;

//alarm[0]
name = get_string("Please enter your name :","");

highscore_add(name,score);

and i also have a obj called death_timer

//create

alarm[0] = 60;

//alarm[0]

room_goto(r_score)
Thanks for your time!
 
T

tobii

Guest
how are you loading and saving the ini?
ah yes sorry, that would be in my death for the player using this code

Code:
if (object_index != obj_player_ship) {
    score += max_armor;   
    if (score > global.highscore) {
        global.highscore = score;
        ini_open("Save.ini");
        ini_write_real("Scores", "Highscore", global.highscore);
        ini_close();
    }
 
T

tobii

Guest
now i get it to draw the score but it always posts 4 instead of my score
 
B

Bayesian

Guest
now i get it to draw the score but it always posts 4 instead of my score
That's probably because the only value in the high score table is what ever the variable "score" is set to when alarm[0] goes off 200 frames after the player is created. You never added the score to the high score table when the player dies using highscore_add(name,score);
ah yes sorry, that would be in my death for the player using this code
You're overwriting the same key position called "Highscore" every time you save. You're also losing the name data because you're not even writing the high score table to the file you're writing global.highscore to it. You should save the high score table to the ini if you want to use draw_highscore() to draw it
Code:
if (object_index != obj_player_ship) {
    score += max_armor;  
    if (score > highscore_value(0)) {
        ini_open("Save.ini");
        for(i=0;i<10;i++){
            ini_write_real("Names",string(i),highscore_name(i))
            ini_write_real("Scores",string(i),highscore_value(i))
        }
        ini_close();
    }
}
You should also load the ini at the start of the game to populate the high score table in a similar fashion.
 
T

tobii

Guest
aah oke thanks man! got it to work, it makes sense now why it was not working before :)

Thank you so much for your time!
 
Top