How to create the score for 2 players?

Roderick

Member
There are a number of different ways, but the common factors are that you need a separate variable for each or an array with one entry for each player, and any time you add points, you need to also get a reference to which player earned them so that you can assign them to the correct variable.
 

Ommn

Member
Do not depend on the "score" variable built-in.
You can create global variables and control them as you wish.
like this:
event create:
GML:
global.score1=0;
global.score2=0;
And to increase the score for player1:
GML:
global.score1+=1;
and to draw score for player1 and player2 in event draw:
GML:
draw_text(50,50,"Player1 = "+string(global.score1))
draw_text(50,150,"Player2 = "+string(global.score2))
 

NewG

Member
It helped me, but now I need to know what to do with the highscore, it happens that the highscore number increases for both players and is not independent of each one, any help?
 

baconlovar

Member
It helped me, but now I need to know what to do with the highscore, it happens that the highscore number increases for both players and is not independent of each one, any help?
do the same thing :)
GML:
global.hscore1 = 0;
global.hscore2 = 0;
 

chamaeleon

Member
it didn't work
Unless it is a state secret it might be beneficial to include all relevant code when saying something does not work. Initialization, updates, drawing. And no pointing to or quoting posts made by others either, because there are no guarantees you are not doing something different or have additional code that affects the result, if it is not a direct copy and paste from your project.
 

NewG

Member
I know this is an old thread, but I have a problem similar to the topic, and it is that I can't create an independent high score for 2 players, any help in this regard?
 

Ommn

Member
welcome again 😊
tell me what is your problem when use the code?
Do not worry.
Some simple code will solve your problem but first tell me what do you want to do?
good luck bro 👍
 

Ommn

Member
GML:
global.score1 = 0;//score player1
global.score2 = 0;//score player2
global.hscore1 = 0;//high score player1
global.hscore2 = 0;//high score player2
If you want to compare between score and high score, use the following code:
GML:
if global.score1>global.hscore1{global.hscore1=global.score1;}
if global.score2>global.hscore2{global.hscore2=global.score2;}
If you want to save the high score even after closing the game to use it when opening the game again:
GML:
ini_open("highscore.ini")
ini_write_real("highscore","player1",global.hscore1)//save high score player1
ini_write_real("highscore","player2",global.hscore2)//save high score player2
ini_close()
and Use this code when you open the game again:
GML:
ini_open("highscore.ini")
global.hscore1=ini_read_real("highscore","player1",0)
global.hscore2=ini_read_real("highscore","player2",0)
ini_close()
I hope it helps you.
 

Japster

Member
and the ini file can be exported in html5?
I can't be sure as not at dev PC atm, but as far as I'm aware you might need to have it in included files for HTML5 (ie. drag a dummy file called that, or a local copy of the actual ini file called that, that your game has now created), into your project workspace and add it that way?

I'm sure one of our many veterans can correct me if I'm wrong! :)
 
Top