• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Problem with simple High Score

Z

zimice15

Guest
Hi,
I have problem with simple HighScore tab .I tried YouTube tutorials.I tried to figure It out and It didn’t get well.Please if you know simple code of HighScore Tab that will save and show saves of players with scores every time the game ends.Player can write score and if score is too low it won’t save and if score is too big it will save on first position.
 

jo-thijs

Member
Hi,
I have problem with simple HighScore tab .I tried YouTube tutorials.I tried to figure It out and It didn’t get well.Please if you know simple code of HighScore Tab that will save and show saves of players with scores every time the game ends.Player can write score and if score is too low it won’t save and if score is too big it will save on first position.
Hi!
It's pretty simple to do once you know how to use: arrays, global variables, for loops and the file_text_*, file_bin_* or ini_* functions.
Which concepts are you familiar with already?

Try to research about the others and then come back with any questions you have left!
 
Z

zimice15

Guest
Thanks for answer.So I made my little research.Now I know what is arrays and I loops.I am familiar with global variables. but I don't really know to figure it out with that loops and arrays and ini files and how player can write into that high score tab .
 

jo-thijs

Member
Thanks for answer.So I made my little research.Now I know what is arrays and I loops.I am familiar with global variables. but I don't really know to figure it out with that loops and arrays and ini files and how player can write into that high score tab .
You can have a global array highscore_entry_score, a global array highscore_entry_name and a global variable highscore_entry_amount.
Ini files are usually not the best idea to store highscores, as players can relatively easily interprete them and cheat.
However, they are the easiest to use in GameMaker (only by a little, but still) and they'll probably suffice for your purposes, so I'll use these.

You can then load highscores from the ini file as follows:
Code:
ini_open("highscores");

global.highscore_entry_amount = 10; // highscore table contains 10 scores
for(var i = global.highscore_entry_amount - 1; i >= 0; --i) {
    global.highscore_entry_name[i] = ini_read_string(string(i + 1), "name", "Not available");
    global.highscore_entry_score[i] = ini_read_real(string(i + 1), "score", 0);
}

ini_close();
and you can save the highscores to the ini file as follows:
Code:
ini_open("highscores");

for(var i = global.highscore_entry_amount - 1; i >= 0; --i) {
    ini_write_string(string(i + 1), "name", global.highscore_entry_name[i]);
    ini_write_real(string(i + 1), "score", global.highscore_entry_score[i]);
}

ini_close();
When you've got a new score S from a player with the name N, you can add this score to the highscore table as follows:
Code:
for(var i = 0; i < global.highscore_entry_amount; ++i) {
    if global.highscore_entry_score[i] < S {
        for(var j = global.highscore_entry_amount - 2; j >= i; --j) {
            global.highscore_entry_name[j + 1] = global.highscore_entry_name[j];
            global.highscore_entry_score[j + 1] = global.highscore_entry_score[j];
        }
        global.highscore_entry_name[i] = N;
        global.highscore_entry_score[i] = S;
        break;
    }
}
As for drawing the highcore table to the screen and getting a name input from the player, there are tons of ways to do that, depending on which UI looks better to you.

For getting a name from the player, you can use the get_string for debugging, as it is the easiest to implement.
You'll want to either use keyboard_string or get_string_async in your final product though.
 
P

pSouper

Guest
Does saving highscores to ini files work for iOS apps too? and android?
 
Z

zimice15

Guest
Ok I’ill try this and and get that name from player.Many Thanks you helped me so much.
 
P

pSouper

Guest
As it turns out, they do work in iOS (not tested on 'droid).

"Why wouldn't they?" - I just couldn't tell from the docs if this function was ios/droid applicable. Not knowing how/whether different platforms allow access to local storage (or other functionality) makes a lot of the docs ambiguous or at least 'not helpful' when debugging code for a function you don't know if it should work or if it is working.

I imagine a lot of noobie issues (and frustrations) may come from not know what to expect in certain situations and therefor unable to narrow the issues down to platform/code/usage etc.

I'm all good now. My game going for app store approval today :) - thanks for ALL your help guys. you've been v.helpful in v.uncertain times.

- Wreck Dive Ralph: Dive Hard

*yet another 8bit ZXSpectrum style game.
 
Top