• 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!

How to add Ingame-Points to global Points?

C

Coleft

Guest
Hey Guys,

I have folllowing problem:

I can't add my ingame points to my global points.
To demonstrate what I mean:

GlobalPoints = X + addTheScoreOfTheLastGame

Can someone help me?

Best regards
Coleft
 
P

Pelican

Guest
I assume you're using a script inside an object to do this?
Try this:
Code:
global.globalPoints+=gameScore
"global." will make sure that globalPoints is adressing a global variable - usually if you don't have a prefix it will instead create a variable of the same name within the object (objectName.globalPoints), which will not be the same variable!
 
D

Dantevus

Guest
Have you checked for any syntax errors? I noticed in your first post you had it listed as "GlobalPoints" rather than "global.points". If it's written that way in your game it wouldn't be addressing the right variable.
 
C

Coleft

Guest
No, I have called it "score", and now I want to add a score which are the scorecounter.
Like if you collect points.
 
F

Facet

Guest
You have to declare it on start

///start event:
global.score = 0;

then
//step event:
if score //here some condition when score should be add
global.score += score; // where score is how many score points

or something like this
 

Yal

🐧 *penguin noises*
GMC Elder
Global as in "sum of all games you've played so far" or global as in "upload to a server where all players store their highscore"? If the former, should the score be reset when you quit the game or be saved?
 
C

Coleft

Guest
I have an object which gives +1 point per click
I have also an Object with Create<Code: score=0
Now I need another counter which counts all these

how?
 
D

Dantevus

Guest
If you're trying to just increment the 'score' variable per click on an object you could use(add "global." before each instance of score if you want multiple items to contribute to the same score):

Left-Click Pressed event (on the object that contributes to the score):
score += 1;

If you're having issues displaying the score on-screen:

Step event (on the object that creates the score):
draw_set_colour('color');
draw_text(x coordinate of display, y coordinate of display, string(score));

Does that help?
 
C

Coleft

Guest
My problem is: The value of points, which I get during the game, changes the global score and doesn't add
Example:

Before Game:
Main Menu Points = 0

Game Start:

Score = 3

After Game:

Main Menu Points = 3

Next Game:
Score = 2

After Game:
Main Menu Points: 2 instead of 3+2=5
 

HayManMarc

Member
You need two separate variables... a 'per-game' score variable and a 'total' score variable. The per-game score variable keeps track of the score during gameplay and is displayed while playing the game. At the end of a game, you add the per-game score to the total score then reset the per-game score variable back to zero before starting the next game. In the main menu, you display the total score variable.
 
C

Coleft

Guest
No I mean, that the global score gets the score of each game
 
D

Dantevus

Guest
I'll write it out how I'd do it:

On my opening room before the game has loaded in the creation code
global.totalscore = 0;

I'd put this somewhere in the play area
Create - > score = 0;

I'd put this on my object being clicked
Left Click Pressed - > score += 1;

I'd then put this on whatever event ends the level before you go to the next room
global.totalscore += score;

That should get you there if I'm understanding your needs correctly.

This will clear the score when you begin the level, and add it to the global total score before the level ends. Then the score will be cleared again and will be incremented and added ad infinitum as much as you need.
 
Top