Legacy GM [SOLVED] Help with High Score Table

K

kuroyuki4

Guest
Hi everyone,

I'm having a problem with a high score table I'm programming for my game. It's intended to show up if the player scores high enough to place somewhere on the table and allow them to enter their initials. However, nothing is being displayed on the table at all (though the player can still "enter" their initials just fine).

The initials are also not being saved at all; there's just blank space there instead of, for example, "E.C". How can I fix this?

Code that selects the position to overwrite:
Code:
if score >= global.entry5Score and score < global.entry4Score
{
global.overwrite = 5
global.entry5Score = score
instance_deactivate_object(self)
exit
}
if score >= global.entry4Score and score < global.entry3Score
{
global.overwrite = 4
global.entry4Score = score
instance_deactivate_object(self)
exit
}
if score >= global.entry3Score and score < global.entry2Score
{
global.overwrite = 3
global.entry3Score = score
instance_deactivate_object(self)
exit
}
if score >= global.entry2Score and score < global.entry1Score
{
global.overwrite = 2
global.entry2Score = score
instance_deactivate_object(self)
exit
}
if score >= global.entry1Score
{
global.overwrite = 1
global.entry1Score = score
instance_deactivate_object(self)
exit
}

Code that is supposed to display the high score table:
Code:
if global.displayHighScores = true
{
{
draw_set_font(global.highScoreFont)
draw_set_color($FFFFFF)
draw_set_halign(fa_center)
format2timeout = string_format(global.timeoutPeriod,2,0)
format8entry1Score = string_format(global.entry1Score,8,0)
format8entry2Score = string_format(global.entry2Score,8,0)
format8entry3Score = string_format(global.entry3Score,8,0)
format8entry4Score = string_format(global.entry4Score,8,0)
format8entry5Score = string_format(global.entry5Score,8,0)
leading0entry1Score = string_replace_all(format8entry1Score," ","0")
leading0entry2Score = string_replace_all(format8entry2Score," ","0")
leading0entry3Score = string_replace_all(format8entry3Score," ","0")
leading0entry4Score = string_replace_all(format8entry4Score," ","0")
leading0entry5Score = string_replace_all(format8entry5Score," ","0")
leading0timeout = string_replace_all(format2timeout," ","0")
}
{
if global.highScoreEntry = true
{
draw_text(112,0,"HIGH SCORES")
draw_text(112,48,"CONGRATULATIONS!")
draw_text(112,80,"ENTER YOUR NAME")
draw_text(112,216,"TIME REMAINING: " + string(leading0timeout))
}
{
if global.overwrite = 1
{
draw_text(112,120,"*1          " + string(leading0entry1Score))
draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
draw_sprite(highScoreCharSet,global.place1,56,120)
draw_sprite(highScoreCharSet,global.place2,64,120)
draw_sprite(highScoreCharSet,global.place3,72,120)
}
if global.overwrite = 2
{
draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
draw_text(112,136,"*2          " + string(leading0entry2Score))
draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
draw_sprite(highScoreCharSet,global.place1,56,136)
draw_sprite(highScoreCharSet,global.place2,64,136)
draw_sprite(highScoreCharSet,global.place3,72,136)
}
if global.overwrite = 3
{
draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
draw_text(112,152,"*3          " + string(leading0entry3Score))
draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
draw_sprite(highScoreCharSet,global.place1,56,152)
draw_sprite(highScoreCharSet,global.place2,64,152)
draw_sprite(highScoreCharSet,global.place3,72,152)
}
if global.overwrite = 4
{
draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
draw_text(112,168,"*4          " + string(leading0entry4Score))
draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
draw_sprite(highScoreCharSet,global.place1,56,168)
draw_sprite(highScoreCharSet,global.place2,64,168)
draw_sprite(highScoreCharSet,global.place3,72,168)
}
if global.overwrite = 5
{
draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
draw_text(112,184,"*5          " + string(leading0entry5Score))
draw_sprite(highScoreCharSet,global.place1,56,184)
draw_sprite(highScoreCharSet,global.place2,64,164)
draw_sprite(highScoreCharSet,global.place3,72,184)
}
}
}
if global.highScoreEntry = false
{
draw_text(112,0,"HIGH SCORES")
draw_text(112,80,"TOP PLAYERS")
draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
draw_text(112,216,"CAN YOU BEAT THE")
draw_text(112,224,"TOP SCORE?")
}
}

The code that replaces the place values with characters is essentially "if argument0 = x {argument0 = string(val)}". Maybe this is why it isn't being saved correctly?

EDIT: I forgot to include the code that's supposed to append the characters.
Code:
if global.overwrite = 1
{
global.entry1Name = string(global.place1 + global.place2 + global.place3)
}
if global.overwrite = 2
{
global.entry2Name = string(global.place1 + global.place2 + global.place3)
}
if global.overwrite = 3
{
global.entry3Name = string(global.place1 + global.place2 + global.place3)
}
if global.overwrite = 4
{
global.entry4Name = string(global.place1 + global.place2 + global.place3)
}
if global.overwrite = 5
{
global.entry5Name = string(global.place1 + global.place2 + global.place3)
}
 
Last edited by a moderator:

CloseRange

Member
Hello!

We don't need to do this now but it looks like this would have been much easier if you had done this with arrays instead of doing global.entry1score global.entry2score ect.
That would have made it look something like this:
Code:
global.entryScore[1] = 0;
global.entryScore[2] = 0;
global.entryScore[3] = 0;
and that would have made it cleaner to work for.

So to start off if nothing is being displayed right its deffinatly a problem in the draw event so i would look there.
It looks like you have a lot of if statments in there so my best guess would be that none of them are being set = to true.

I took the code and put it in a script and there where a lot of unessisary curly brackets so i cleaned it up :rolleyes: I'm guessing you used to code in another language? I've seen other programmers make their code look very simmilar.

Anyway this is the cleaned up version i made there are no changes to it that would "fix" the problem so no need to use or even look at it if you want but in case you do:
Code:
/// TEST



if global.displayHighScores = true
{
    draw_set_font(global.highScoreFont)
    draw_set_color($FFFFFF)
    draw_set_halign(fa_center)
    format2timeout = string_format(global.timeoutPeriod,2,0)
    format8entry1Score = string_format(global.entry1Score,8,0)
    format8entry2Score = string_format(global.entry2Score,8,0)
    format8entry3Score = string_format(global.entry3Score,8,0)
    format8entry4Score = string_format(global.entry4Score,8,0)
    format8entry5Score = string_format(global.entry5Score,8,0)
    leading0entry1Score = string_replace_all(format8entry1Score," ","0")
    leading0entry2Score = string_replace_all(format8entry2Score," ","0")
    leading0entry3Score = string_replace_all(format8entry3Score," ","0")
    leading0entry4Score = string_replace_all(format8entry4Score," ","0")
    leading0entry5Score = string_replace_all(format8entry5Score," ","0")
    leading0timeout = string_replace_all(format2timeout," ","0")
    if global.highScoreEntry = true {
        draw_text(112,0,"HIGH SCORES")
        draw_text(112,48,"CONGRATULATIONS!")
        draw_text(112,80,"ENTER YOUR NAME")
        draw_text(112,216,"TIME REMAINING: " + string(leading0timeout))
    }
    if global.overwrite = 1 {
        draw_text(112,120,"*1          " + string(leading0entry1Score))
        draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
        draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
        draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
        draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
        draw_sprite(highScoreCharSet,global.place1,56,120)
        draw_sprite(highScoreCharSet,global.place2,64,120)
        draw_sprite(highScoreCharSet,global.place3,72,120)
    }
    if global.overwrite = 2 {
        draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
        draw_text(112,136,"*2          " + string(leading0entry2Score))
        draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
        draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
        draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
        draw_sprite(highScoreCharSet,global.place1,56,136)
        draw_sprite(highScoreCharSet,global.place2,64,136)
        draw_sprite(highScoreCharSet,global.place3,72,136)
    }
    if global.overwrite = 3 {
        draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
        draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
        draw_text(112,152,"*3          " + string(leading0entry3Score))
        draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
        draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
        draw_sprite(highScoreCharSet,global.place1,56,152)
        draw_sprite(highScoreCharSet,global.place2,64,152)
        draw_sprite(highScoreCharSet,global.place3,72,152)
    }
    if global.overwrite = 4 {
        draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
        draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
        draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
        draw_text(112,168,"*4          " + string(leading0entry4Score))
        draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
        draw_sprite(highScoreCharSet,global.place1,56,168)
        draw_sprite(highScoreCharSet,global.place2,64,168)
        draw_sprite(highScoreCharSet,global.place3,72,168)
    }
    if global.overwrite = 5 {
        draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
        draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
        draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
        draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
        draw_text(112,184,"*5          " + string(leading0entry5Score))
        draw_sprite(highScoreCharSet,global.place1,56,184)
        draw_sprite(highScoreCharSet,global.place2,64,164)
        draw_sprite(highScoreCharSet,global.place3,72,184)
    }
    if global.highScoreEntry = false {
        draw_text(112,0,"HIGH SCORES")
        draw_text(112,80,"TOP PLAYERS")
        draw_text(112,120,"*1 " + string(global.entry1Name) + "      " + string(leading0entry1Score))
        draw_text(112,136,"*2 " + string(global.entry2Name) + "      " + string(leading0entry2Score))
        draw_text(112,152,"*3 " + string(global.entry3Name) + "      " + string(leading0entry3Score))
        draw_text(112,168,"*4 " + string(global.entry4Name) + "      " + string(leading0entry4Score))
        draw_text(112,184,"*5 " + string(global.entry5Name) + "      " + string(leading0entry5Score))
        draw_text(112,216,"CAN YOU BEAT THE")
        draw_text(112,224,"TOP SCORE?")
    }
}

as for the saving of them how have you tried saving the data? are you using "game_save()" or ini files? (I would higly recommend ini files)

I understand this isn't a full solve of your problem but none the less I hope it helps! :D If not or if you have any further questions about anything at all don't be afraid to ask and ill do my best to help you! :)
-CloseRange
 
K

kuroyuki4

Guest
I never knew about arrays. I should really look into using those. As for programming in another language, I only really messed with batch files and the like when I was younger, so I never really learned how to code properly. :oops:

I've been saving the data using .ini files, which has worked well so far. I'll go back and make sure everything is being defined properly. It's replacing the score in the correct place (so if position 3 has 60000 and I scored 65000, that's being saved correctly). It's just the initials that don't work. I'll go look at my code again and see where things are going wrong. Thanks for helping!
 

CloseRange

Member
Hey no problem! if you still can't figure it out after taking another look at it ill try to help more! If you need help with anything else at all dont be afraid to ask me and ill do my best!

PS don't worry it's never too late to learn :p
 
K

kuroyuki4

Guest
When I checked the debugger, it seems global.overwrite isn't being set to the correct value by the time the table is created. After a little bit of checking, it seems I accidentally set it to zero in the table object's create event! Silly me. It now draws the table as intended (though there is some glitchiness due to some incomplete programming).

The initials are still not being saved correctly though. I think it has something to do with the way I'm trying to do it. I have 3 "place" values that save the character when the fire button is pressed, and they're supposed to be converted to their corresponding letter when saved, but it doesn't quite do that. Since I'm using a custom font as well, would there be simple a way to do this?
 

CloseRange

Member
I'm going to be honest i'm not sure what you meant I'm not fully here today :oops:
i'm assuming you're saying you are saving each individual letter in a separate variable?? If so that's no good, too much work haha

best way id say is just try something like this:
Code:
initials = keyboard_string;
if string_length( initials ) > 3 {
     keyboard_string = string_copy( initials, 1, 3 );
}
keyboard_string is a list of all the last letters/numbers/characters the player has typed.
string_copy will basically make it so if the max letters the player can use is 3.

Hopefully this is what you're looking for if not ill try something else :)
 
K

kuroyuki4

Guest
Sorry, I have trouble explaining things. It's more like the individual characters are inputted through the arrow keys and the fire button, instead of being typed in. Each individual variable is supposed to store the characters separately, which is probably really inefficient.
 

CloseRange

Member
ok i think i understand now and it's not the worst but that probobly would be better with arrays.
here is what you should probobly do. go to the create event (doesn't really matter where but probboly best in high score object) and make an array like this:
Code:
letter[1] = "A";
letter[2] = "B";
letter[3] = "C";
letter[4] = "D";
letter[5] = "E";
letter[6] = "F";
letter[7] = "G";
letter[8] = "H";
letter[9] = "I";
letter[10] = "J";
letter[11] = "K";
letter[12] = "L";
letter[13] = "M";
letter[14] = "N";
letter[15] = "O";
letter[16] = "P";
letter[17] = "Q";
letter[18] = "R";
letter[19] = "S";
letter[20] = "T";
letter[21] = "U";
letter[22] = "V";
letter[23] = "W";
letter[24] = "X";
letter[25] = "Y";
letter[26] = "Z";

then make a variable called current_letter to represent what "letter" you want to add:
Code:
current_letter = 1;
then in the step event check for pushing up or down and add/subtract 1 from current_letter:

Code:
if keyboard_check_pressed(vk_up) {
        current_letter++
}
if keyboard_check_pressed(vk_down) {
        current_letter--
}
current_letter = clamp(current_letter, 1, 26);
the clamp function is just used so they cant go beyond 26 or below 1


finally you can go to draw event and do this:
Code:
draw_text(x, y, letter[current_letter]);
and so if current_letter was, say, 5 then it would draw the letter "E"
now obviously this isn't perfect because it's just to show you the basics behind arrays.

youll probobly want to make 3 variables to store each letter of the players initials.
 
K

kuroyuki4

Guest
It works now. Thank you so much! I've been wracking my brain about this for days now. I'm glad you helped me find a way to fix it.
 
Top