• 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 How to make custom highscore?

A

Artwark

Guest
I have currently finished a game and for now, I've used a highscore table in studio that has a pop up per time you get a game over.

How do I make a custom highscore here? By this, I mean to make a highscore without that windows pop up that often shows up.

According to one of the guys in gamedev I talked to, he suggested me to learn more on data structures.

Quite frankly, I'm not very skilled in programming and I'm not able to fully understand data structures that much.

So is it possible to make a custom highscore in studio?
 

TehCupcakes

Member
This is a fairly simple task, and the person you talked to was right on target when he suggested you learn about data structures.

However, I understand that they can be confusing at first for some people, especially because of the particular functions GM:S uses to implement them. I think learning arrays might be an easier way for you to accomplish this task. Although they are conceptually very similar to data structures, the syntax to use them is a bit more straight-forward.

If you are unsure on how to use arrays, I suggest you read up on them in the manual. In fact, while you're at it you should probably read the manual entries for ds_list and ds_map if you haven't already. The manual is typically the best place to start for any problem you're having with Game Maker: Studio. Once you have fully read the explanation in there and tried your hand at implementing it, if you are still struggling, then you can come here and post specifics about which pieces you are having trouble with.

Good luck! :)
 
T

TDSrock

Guest
I wrote out a tutorial regarding 1D and 2D arrays a while back on the old GMC. You might want to check it out HERE.
 
A

Artwark

Guest
Ok so I tried to do my own thing here (well actually, its from a simple tutorial but not from the previous post though I am trying that as well)

And this is what I came up with so far.....

obj_highscore

Create Event

ini_open("dum.ini")

score_create = ds_grid_create(1,3);

ds_grid_set(score_create,0,0,ini_read_real('highscores','score1','0'))

ds_grid_set(score_create,0,1,ini_read_real('highscores','score2','1'))

ds_grid_set(score_create,0,2,ini_read_real('highscores','score3','2'))

ini_close()

game_score = 0;

Step Event

for(a = 0; a<3; a+=1)

{

if game_score>ds_grid_get(score_create,0,a)

{

for(b = 3; b>=a; b-=1)

{

ds_grid_set(score_create,0,b,ds_grid_get(score_create,0,b-1))

if b = 0

{

break;

}

ds_grid_set(score_create,0,a,game_score)

break;

}

}

}

ini_open("dum.ini")

score1=ini_write_real('highscores','score1',ds_grid_get(score_create,0,0))

score2=ini_write_real('highscores','score1',ds_grid_get(score_create,0,1))

score3=ini_write_real('highscores','score1',ds_grid_get(score_create,0,2))

ini_close()

Draw Event

i = 0;

while i<5

{

draw_text(x,y+20*i,ds_grid_get(score_create,0,i))

i+=1

}

But I'm still not getting only just three slots as well as including the level number which is global.level.

Any idea what problem I have here?

Also, I'd like to know how exactly I should put code tags so that my code can be easily read by others if that's possible.
 

jo-thijs

Member
5 comments:
1) You save 3 times to 'score1' and never to 'score2' or 'score3'
2) The step event should only be executed when you want to submit a new score, not every step, as a new score would instantly take up all 3 places.
3) In your draw event, you let i go until i < 5, while you should let it go to i < 3
4) You use strings rather than numbers as third argument of ini_read_real.
5) These 2 lines:
Code:
ds_grid_set(score_create,0,a,game_score)
break;
should be put a curly bracket } lower.

EDIT:
Sorry, forgot your last question.
Those code tags are called comments and you can use them like this:
code // comment

or like this:
/*
comment
comment
comment
*/
code
 
Last edited:
A

Artwark

Guest
5 comments:
1) You save 3 times to 'score1' and never to 'score2' or 'score3'
2) The step event should only be executed when you want to submit a new score, not every step, as a new score would instantly take up all 3 places.
3) In your draw event, you let i go until i < 5, while you should let it go to i < 3
4) You use strings rather than numbers as third argument of ini_read_real.
5) These 2 lines:
Code:
ds_grid_set(score_create,0,a,game_score)
break;
should be put a curly bracket } lower.

EDIT:
Sorry, forgot your last question.
Those code tags are called comments and you can use them like this:
code // comment

or like this:
/*
comment
comment
comment
*/
code
Ok....I'm still unable to get that zero record the newest score value that global.points is having.....

I fixed point 3 and it worked but I can't understand the 2nd point.....I think I'm stuck here. I tried fixing the other things but still nothing happens. Atleast now it doesn't show an error....
 

jo-thijs

Member
When do you want to add a new score?
I'm guessing when it's game over.
What you've got in the step event now shouldn't be executed in the step event, but should only be executed once when its game over.
Otherwise, you'll keep adding the highscore every step, pushing the other scores away.
 
A

Artwark

Guest
When do you want to add a new score?
I'm guessing when it's game over.
What you've got in the step event now shouldn't be executed in the step event, but should only be executed once when its game over.
Otherwise, you'll keep adding the highscore every step, pushing the other scores away.
Yes, the new score should be added when the game over appears.

So if it shouldn't be in the step event, where should it be?

So basically the way you get the game over screen is like this.

obj_asteroids

collision with ship

//when losing life and when all lives are gone
if(global.life > 0)
{
instance_create(room_width/2,room_height/2,obj_playerspawn);
instance_destroy();
global.life -=1;
}
else
{
instance_create(0,0,obj_gameover);
}
instance_destroy();
}

the obj_game over simply just goes to the next room which is rm_highscore.

To be honest here....I'm kinda stuck what to do now.

So instead of the step event, I have to put it on the create event instead?
 

jo-thijs

Member
Create event could work, but you should put it inside an if, so that it only executes if it is supposed to be added.
Have some global variable "global.addhighscore" set to false on the main menu of your game and set it to true when it's game over.
Then you only use the current step event once in the create event if this global variable is true.
 
Top