• 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 Help using INI files to store high scores.

Q

Quelandoris

Guest
Hello, I'm currently trying to make a persistent local scoreboard for a game I'm working on. I'm fairly sure I have most of my code right, as it loads the default values, saves those to an INI file when there is no INI file to be found, and shows those values on the end-screen, but whenever i try to enter a new high score, it doesn't show that value on the next run, instead showing the default again.

relevant code is as follows:

Score object:
Create Event:
Code:
myScore=0;
newString = "";
if(file_exists("score.ini")){
    ini_open("score.ini");
    scores = ds_grid_create(2,5);
    ds_grid_read(scores,ini_read_string("Scores","Score_array","Broken"));
    ini_close();
}
else{
    scores = ds_grid_create(2,5);
    ds_grid_set(scores,0,0,"Kai");
    ds_grid_set(scores,1,0,7000);
    ds_grid_set(scores,0,1,"Quelandoris");
    ds_grid_set(scores,1,1,6820);
    ds_grid_set(scores,0,2,"Abstract");
    ds_grid_set(scores,1,2,5550);
    ds_grid_set(scores,0,3,"Rishella");
    ds_grid_set(scores,1,3,4130);
    ds_grid_set(scores,0,4,"LuuKaire");
    ds_grid_set(scores,1,4,3950);
    ini_open("score.ini");
    ini_write_string("Scores","Score_array", ds_grid_write(scores));
    ini_close();
}
press <Enter> Event:
Code:
if(room==newScore && string_length(keyboard_string)>1){
    newString=keyboard_string;
    if(newScore>ds_grid_get(scores,1,0)){
        ds_grid_set(scores,0,4,ds_grid_get(scores,0,3));
        ds_grid_set(scores,1,4,ds_grid_get(scores,1,3));
        ds_grid_set(scores,0,3,ds_grid_get(scores,0,2));
        ds_grid_set(scores,1,3,ds_grid_get(scores,1,2));
        ds_grid_set(scores,0,2,ds_grid_get(scores,0,1));
        ds_grid_set(scores,1,2,ds_grid_get(scores,1,1));
        ds_grid_set(scores,0,1,ds_grid_get(scores,0,0));
        ds_grid_set(scores,1,1,ds_grid_get(scores,1,0));
        ds_grid_set(scores,0,0,newString);
        ds_grid_set(scores,1,0,myScore);
    }
    else if(newScore>ds_grid_get(scores,1,1)){
        ds_grid_set(scores,0,4,ds_grid_get(scores,0,3));
        ds_grid_set(scores,1,4,ds_grid_get(scores,1,3));
        ds_grid_set(scores,0,3,ds_grid_get(scores,0,2));
        ds_grid_set(scores,1,3,ds_grid_get(scores,1,2));
        ds_grid_set(scores,0,2,ds_grid_get(scores,0,1));
        ds_grid_set(scores,1,2,ds_grid_get(scores,1,1));
        ds_grid_set(scores,0,1,newString);
        ds_grid_set(scores,1,1,myScore);
    }
    else if(newScore>ds_grid_get(scores,1,2)){
        ds_grid_set(scores,0,4,ds_grid_get(scores,0,3));
        ds_grid_set(scores,1,4,ds_grid_get(scores,1,3));
        ds_grid_set(scores,0,3,ds_grid_get(scores,0,2));
        ds_grid_set(scores,1,3,ds_grid_get(scores,1,2));
        ds_grid_set(scores,0,2,newString);
        ds_grid_set(scores,1,2,myScore);
    }
    else if(newScore>ds_grid_get(scores,1,3)){
        ds_grid_set(scores,0,4,ds_grid_get(scores,0,3));
        ds_grid_set(scores,1,4,ds_grid_get(scores,1,3));
        ds_grid_set(scores,0,3,newString);
        ds_grid_set(scores,1,3,myScore);
    }
    else if(newScore>ds_grid_get(scores,1,4)){
        ds_grid_set(scores,0,4,newString);
        ds_grid_set(scores,1,4,myScore);
    }
    ini_open("score.ini");
    ini_write_string("Scores","Score_array", ds_grid_write(scores));
    ini_close();
    ds_grid_destroy(scores);
    room_goto(Start);
    with(bkg_ob) instance_destroy();
    instance_destroy();
}
Any help or explanation would be appreciated. Thanks in advance!
 
When I tested how to work with ini I had the same issue and hopefully the same reason why: I didn't include the ini first.
So what I did: create a file called score.txt and write the basic settings in there. Then I changed the file type from .txt to .ini and imported it to my project as included file.
All of a sudden everything worked as expected.

Hope that solves your issue as well.
 
Q

Quelandoris

Guest
When I tested how to work with ini I had the same issue and hopefully the same reason why: I didn't include the ini first.
So what I did: create a file called score.txt and write the basic settings in there. Then I changed the file type from .txt to .ini and imported it to my project as included file.
All of a sudden everything worked as expected.

Hope that solves your issue as well.
Okay, what basic settings to I need to include? Just the string of numbers containing my grid?
 
Just try to include an empty ini and see if it works. I think you just need to ahve an ini with that name included - that's all. I only added my default values to the imncluded ini because I actually wanted to be able to change those from outside so I can just push a new ini to change settings.

Once you have the ini included, your code might need some adaption because I guess file_exists will return true for included files. But you could check for a section that won't appear in the included file.

Mind I'm doing this from memory. I might be wring with a couple of stuff
 
Top