Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411643 Posts in 69394 Topics- by 58450 Members - Latest Member: pp_mech

May 14, 2024, 07:30:48 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsHigh Score Lists in Game Maker!
Pages: [1]
Print
Author Topic: High Score Lists in Game Maker!  (Read 20646 times)
ink.inc
Guest
« on: November 18, 2011, 11:54:18 PM »

In the following example, I show you how to load numbers from an .ini file, determine if the current score is higher than any of the high scores, and then rewrite the .ini file accordingly.

To start with, create the ini file. To do so, open up Notepad and save it as "name.ini". In the following example, I named the file "dum.ini"

You can set the .ini up as such:

Quote
[highscores]
score1 = 0
score2 = 0
score3 = 0
score4 = 0
score5 = 0

What you have just done is created a file with 5 variables, each capable of holding high scores. Score1 will hold the highest, score2 will hold the second highest, etc, etc. NOTE THAT THE INI MUST BE IN THE SAME FOLDER AS THE GAME.

The following will require you to use GML, but I've set it up so that you can just copy/paste the code into a control object.

In the Create Event:
Code:
ini_open("dum.ini")//opens the .ini file for the data to be read
score_grid=ds_grid_create(1,5)//creates a data grid that holds the values of the high scores
ds_grid_set(score_grid,0,0,ini_read_real('highscores','score1',''))//sets the values of the datagrid
ds_grid_set(score_grid,0,1,ini_read_real('highscores','score2',''))
ds_grid_set(score_grid,0,2,ini_read_real('highscores','score3',''))
ds_grid_set(score_grid,0,3,ini_read_real('highscores','score4',''))
ds_grid_set(score_grid,0,4,ini_read_real('highscores','score5',''))
ini_close()//close the .ini; this is important
game_score=0//the current players score

Put this code when the round has ended.
Code:
//sets up a while loop that checks the value of the current score with every single one of the high scores. 
a=0 //the current ranking of the score being checked. it starts at 0 because data grid numbering starts at 0

while a<5 //while a<the number of items in the data grid
    {
    if game_score>ds_grid_get(score_grid,0,a)//if the score is higher than this number
        {
        b=4
        //this code slides down all the values of the high scores. so if your score is
        //the new highest score, score 5 is set to score 4, score 4 is set to score 3, etc.
        while b>=a
            {
            ds_grid_set(score_grid,0,b,ds_grid_get(score_grid,0,b-1))   
            b-=1
            if b=0
                break;//if you've run through all the numbers, QUIT
            }
        ds_grid_set(score_grid,0,a,game_score)
        break;//if you've set the new score, QUIT
        }
    a+=1
    }
ini_open("dum.ini")//WRITE THE NEW VALUES TO INI FILE
score1=ini_write_real('highscores','score1',ds_grid_get(score_grid,0,0))
score2=ini_write_real('highscores','score2',ds_grid_get(score_grid,0,1))
score3=ini_write_real('highscores','score3',ds_grid_get(score_grid,0,2))
score4=ini_write_real('highscores','score4',ds_grid_get(score_grid,0,3))
score5=ini_write_real('highscores','score5',ds_grid_get(score_grid,0,4))
ini_close()

Assuming you want to draw it, put this in the Draw Event.
Code:
i=0
        while i<5
            {
            draw_text(x,y+20*i,ds_grid_get(score_grid,0,i))
            i+=1
            }

Have fun!
« Last Edit: November 19, 2011, 11:31:32 PM by John Sandoval » Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #1 on: November 19, 2011, 12:04:29 AM »

now do an online hi score list with facebook api options to see the scores of all your friends
Logged

moi
Level 10
*****


DILF SANTA


View Profile WWW
« Reply #2 on: November 19, 2011, 03:46:40 AM »

facebook is so 2010
Logged

subsystems   subsystems   subsystems
Soulliard
Level 10
*****


The artist formerly known as Nightshade


View Profile WWW
« Reply #3 on: November 19, 2011, 10:29:59 AM »

I normally use .ini files for game settings instead of high scores, because the .ini file is easy to modify with any text editor. GM's default high score functions actually work pretty well, as long as you don't use the default high score popup window.
Logged

Shackhal
Level 9
****


Like a child with toys


View Profile WWW
« Reply #4 on: November 21, 2011, 09:41:16 PM »

That's was a good opportunity to post a tutorial Cheesy

I only have a question. The code when the high score is updated (the second one), in what kind of event we need to put it? Because a step event will create a loop and all the positions will be overwritten by the new highscore...
Logged

 
sedna16
Level 0
**


View Profile
« Reply #5 on: November 21, 2011, 10:29:39 PM »

you can create a variable that will stop the loop and place it in an IF statement

like

stop_loop = 0; // 1 - go on ; 0 - stop
Logged
Shackhal
Level 9
****


Like a child with toys


View Profile WWW
« Reply #6 on: November 21, 2011, 11:43:36 PM »

you can create a variable that will stop the loop and place it in an IF statement

like

stop_loop = 0; // 1 - go on ; 0 - stop

I was thinking about that. And that variable must reset when the high-score list need to be update.
Logged

 
eyeliner
Level 10
*****


I'm afraid of americans...


View Profile
« Reply #7 on: November 25, 2011, 07:57:05 AM »

I like these small tutorials.

*cracks the whip*

MOAR!
« Last Edit: November 25, 2011, 08:20:04 AM by eyeliner » Logged

Yeah.
volando
Level 0
**


View Profile WWW
« Reply #8 on: May 13, 2012, 05:09:02 AM »

I would like to know what tools are used to set this scores online. somewhere. I am looking after that but still don't find anything. 39dll looks good but still hard to get to it.
Logged
poe
Guest
« Reply #9 on: May 13, 2012, 07:13:00 AM »

If anyone wants it, I have a mostly finished online high score list thing that should work with any framework. However people can submit scores they didn't earn if they get the URL. I just always figured my games won't take off so no one will bother cheating Smiley
Logged
Desert Dog
Level 4
****



View Profile
« Reply #10 on: May 13, 2012, 05:19:29 PM »

If anyone wants it, I have a mostly finished online high score list thing that should work with any framework. However people can submit scores they didn't earn if they get the URL. I just always figured my games won't take off so no one will bother cheating Smiley

My games didn't take off, and people still cheated.  Shrug
Logged

Sharkoss
Level 3
***



View Profile
« Reply #11 on: May 14, 2012, 08:38:49 PM »

I would like an online hi-score list for Game Maker, yes.  If you can make it tricky to exploit, I will pay you in hugs and/or cock pics.
Logged
ink.inc
Guest
« Reply #12 on: May 14, 2012, 08:42:12 PM »

An intriguing proposition.
Logged
poe
Guest
« Reply #13 on: May 18, 2012, 06:34:42 PM »

http://calibtothemoon.com/downloads/highscore.rar

Wrote up a small documentation, but I may have forgotten things/done them wrong. Let me know if there's any issues and whatnot. I will be happy to help Smiley
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic