• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

ini-problems (no update and unpleasant list display)

Hi programmers.

I´ve got problems with ini-handling.
I have a highscore table in my game.

What I want:

A saved highscore list on each unit - every time you restart
the game, the ranking of the best players (TOP - 10) is reloaded.
The list shows up to 10 names with the scores, vertically listet.

What goes wrong:

- Every time the game is turned off and restarted again, the
highscore list is set on "empty" again, and 0 points. And
just one "empty" is listed. But I wanted to have a list with
10 ranking rows, not 1.

- When I played a game once again and when I enter my name
into the highscore list again, I see two results put into that one
row, both names and scores are overlapping.

Here the codes...

First invisible room, global-variable-settings,
unsprited object contains this:


Code:
CREATE

ini_open("HighScore.ini");
for (i = 0; i < 10; i++)
    {
        global.score_array[i, 0] = "<EMPTY>"; // name
        global.score_array[i, 1] = 0;    // score
    }
room_goto_next();
After playing game (game over) another invisible room
with another unsprited object contains that:


Code:
ini_open("HighScore.ini");
for (i = 0; i < 10; i++)
    {
        global.score_array[i, 0] = ini_read_string(string(i), "NAME", "<EMPTY>");
        global.score_array[i, 1] = ini_read_real(string(i), "SCORE", 0);
    }
ini_close();


for (i = 0; i < 10; i++)
{
    if (score > global.score_array[i, 1])
    {
        room_goto(LV_00_END_HSEntry);
    }
    else{
        room_goto(LV_00_END_noHS);
    }
}
Room "LV_00_END_noHS goes directly to the Highscore-Room (viewing highscore).
Room "LV_00_END_HSEntry" has an ENTER-object with these codes:

Code:
CREATE

image_index = 0;
image_speed = 0;
if !audio_is_playing(au_HighscoreSound){
    audio_play_sound(au_HighscoreSound,1,true);
}
letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890@*?!&_+-"
position = 1;
name = "";
limit = 12;
w = room_width/2;
h = room_height/2;


STEP

if keyboard_check_pressed(vk_right){
    position += 1;
    if position>string_length(letter){
        position = 1;
    }
}

if keyboard_check_pressed(vk_left){
    position -= 1;
    if position < 1 {
        position = string_length(letter)}
}

if keyboard_check_pressed(vk_down){
    if string_length(name)<limit {
        name += string_char_at(letter, position)}
}

if keyboard_check_pressed(vk_up){
    name = string_delete(name, string_length(name), 1)}
 

DRAW

draw_set_font(Kiddybox_Font3);
draw_set_halign (fa_center);
draw_set_valign (fa_center);
draw_text(w, h+65, name);

draw_set_font(Kiddybox_Font4);
draw_set_halign (fa_center);
draw_set_valign (fa_center);
draw_text(w, h-54, string_char_at(letter, position));


PRESS-ENTER-EVENT

global.name = name;

ini_open("HighScore.ini");
for (i = 0; i < 10; i++)
    {
        global.score_array[i, 0] = ini_read_string(string(i), "NAME", "<EMPTY>");
        global.score_array[i, 1] = ini_read_real(string(i), "SCORE", 0);
    }
ini_close();

for (i = 0; i < 10; i++){
    if (score>global.score_array[i, 1]){
        for (j = 9; j > i; j--){
            global.score_array[j, 0] = global.score_array[j-1,0];
            global.score_array[j, 1] = global.score_array[j-1,0];}
         
            global.score_array[i, 0] = global.name;
            global.score_array[i, 1] = score;
            break;
        }
    }

ini_open("HighScore.ini")
for (i = 0; i < 10; i++){
    ini_write_string(string(i), "NAME", global.score_array[i,0]);
    ini_write_real(string(i), "SCORE", global.score_array[i,1]);
}
ini_close();

room_goto(Highscore);
Room "Highscore" has an unsprited object with that code:
Code:
DRAW

xx = room_width/2 - 85;
yy = 175;
draw_set_color(c_white);
draw_set_font(Kiddybox_Font3);
draw_set_halign(fa_center);
draw_set_valign(fa_top);
for (i = 0; i < 10; i++){
    draw_text(xx, yy, string(global.score_array[i,0]));
    draw_text(xx + 195, yy, string(global.score_array[i,1]));
}
Has anybody an idea where the problem could be?
Thankfully greetings,
Archie.
 

TailBit

Member
Hm, missing a ini_close() in the first block.. Shouldn't have to load the list that many times

And it doesn't seem to load the highscores early, so if you access room highscore it wouldn't have the stored values..

Should load it into the global array at the start, and save after it have been rearranged.. Shouldn't be nessesary to load it that many times.
 
Top