Help with high scores

samspade

Member
I am attempting to add values into highscores through an a loop that takes my values from a ds list and puts them into the highscore_add but this isnt working as the highscore_draw only outputs undefined under name and 0 for score. here is the code :
/// add users highscore to array
if (obj_player.rm=1){
ds_list_add(scorelist,playerscore);
object_set_visible(obj_score,true)
ds_list_sort(scorelist,false);
for (k=0;k<=ds_list_size(scorelist);k+=1){
highscore_add(string(k),ds_list_find_value(scorelist,k));
}
}

please help and thank you in advance
Couple things. First, using code brackets and indentations make things a lot easier to read; however, this code isn't very long so it's not that bad. Second, it should be == not = in the if statement. That won't cause an error here, but it's still technically wrong and will cause an error in other languages and possibly certain complies of Game Maker? I can't remember. Third, if that 1 is supposed to stand for true, you should use true, not 1. Again, won't cause an error, but it's easier to read. If it really is supposed to be the number 1 you could leave it. Although the way game maker handles numbers might eventually cause a problem as there may come a point where 1 isn't actually equal to exactly 1.

A couple other general points. your for loop will likely go to far. It should just be k < ds_list_size(scorelist) not <=. You should also probably use var k, not k, in the for loop as there doesn't seem to be any reason why k shouldn't be a local var here.

Regarding the actual question (sorry it took me so long to get there) I'm unclear as to why you're using the built in highscore system and you're own ds_list. I would either create your own highscore system or use only the functions related to game maker's high score function. Also, it would be helpful to see how you're drawing the high score list. However, the error seems to imply that there's something wrong in the for loop. I would use the debugger or show debug message to find out what is going on. It actually looks correct to me, or that at least it should output something. Which might mean you're never making it inside the loop to start with or that something elsewhere is over writing it.
 
B

Bigbhamber

Guest
Couple things. First, using code brackets and indentations make things a lot easier to read; however, this code isn't very long so it's not that bad. Second, it should be == not = in the if statement. That won't cause an error here, but it's still technically wrong and will cause an error in other languages and possibly certain complies of Game Maker? I can't remember. Third, if that 1 is supposed to stand for true, you should use true, not 1. Again, won't cause an error, but it's easier to read. If it really is supposed to be the number 1 you could leave it. Although the way game maker handles numbers might eventually cause a problem as there may come a point where 1 isn't actually equal to exactly 1.

A couple other general points. your for loop will likely go to far. It should just be k < ds_list_size(scorelist) not <=. You should also probably use var k, not k, in the for loop as there doesn't seem to be any reason why k shouldn't be a local var here.

Regarding the actual question (sorry it took me so long to get there) I'm unclear as to why you're using the built in highscore system and you're own ds_list. I would either create your own highscore system or use only the functions related to game maker's high score function. Also, it would be helpful to see how you're drawing the high score list. However, the error seems to imply that there's something wrong in the for loop. I would use the debugger or show debug message to find out what is going on. It actually looks correct to me, or that at least it should output something. Which might mean you're never making it inside the loop to start with or that something elsewhere is over writing it.
so i made some changes you suggested( besides the rm=1 because i actually need to use numbers). also regarding your question about where the draw code is for the scoreboard, it is within another object which sole purpose is to draw the score.
the code is: draw_highscore(100,100,500,500)

the code does draw the scoreboard but fails to fill it in with the players score. finally the reason i used the ds_list and the built in high score method is that this game is for an school assignment and i must include something that is similar to an arraylist from java which is where the ds_list comes in but i could not figure out means of outputting the score without the highscore function so i included it in my code. if there is a method to create a similar highscore ranking using only the ds_list could you please explain.
 

samspade

Member
so i made some changes you suggested( besides the rm=1 because i actually need to use numbers). also regarding your question about where the draw code is for the scoreboard, it is within another object which sole purpose is to draw the score.
the code is: draw_highscore(100,100,500,500)

the code does draw the scoreboard but fails to fill it in with the players score. finally the reason i used the ds_list and the built in high score method is that this game is for an school assignment and i must include something that is similar to an arraylist from java which is where the ds_list comes in but i could not figure out means of outputting the score without the highscore function so i included it in my code. if there is a method to create a similar highscore ranking using only the ds_list could you please explain.
In that case, I would not use the highscore functions. I would just do everything with a list. Here's one way to draw a list:

Code:
///draw event or draw GUI event
var spacing = 20;
for (var i = 0; i < ds_list_size(scorelist); i += 1) {
    draw_text(100, 500 + (i * spacing), scorelist[| i]);
}
If you need something more complete, there are a lot of youtube videos that use lists, arrays, or grids for highscore features in game maker. Watching some of those would be helpful.
 
B

Bigbhamber

Guest
In that case, I would not use the highscore functions. I would just do everything with a list. Here's one way to draw a list:

Code:
///draw event or draw GUI event
var spacing = 20;
for (var i = 0; i < ds_list_size(scorelist); i += 1) {
    draw_text(100, 500 + (i * spacing), scorelist[| i]);
}
If you need something more complete, there are a lot of youtube videos that use lists, arrays, or grids for highscore features in game maker. Watching some of those would be helpful.
hi thank you for your suggestion but i have another question. i found a small error caused my original code to not output scores but not, it fills the list with scores and in the name slate(which was supposed to be the ranking number rather than a name) is randomized order for example: it outputs 0 then another 0 then 1 than 3. so im wondering if there are thing that may cause this issue.
here is the code:
/// add users highscore to array
if (obj_player.rm=1){
ds_list_add(scorelist,playerscore);
object_set_visible(obj_score,true)
ds_list_sort(scorelist,false);
var k;
obj_player.rm=0;
for (k=0;k<ds_list_size(scorelist);k++){
highscore_add(string(k),ds_list_find_value(scorelist,k));
}
}

the image attached below is how it outputs after only 1 run of the game
 

Attachments

Last edited by a moderator:
Top