lives and scores

Get help using Construct 2

Post » Wed Dec 07, 2011 6:26 pm

Hi,

I set two texts one for the lives and the other for the scores both of them are global and connected to global variables, but while I'm testing my game:

1. first it was working fine and every time the player die the lives reduce 1
2. when it reaches to lives<0 the game will go to the end layout.
3. when i press the space, the game will start again.

The problem is when it starts again, the two texts (lives and scores) disappeared.

How can i fix it?
B
303
S
6
G
5
Posts: 163
Reputation: 12,152

Post » Wed Dec 07, 2011 6:45 pm

Please, upload your capx file. It will help us to understand what is happening :)
B
15
S
4
G
6
Posts: 9
Reputation: 3,944

Post » Wed Dec 07, 2011 6:55 pm

@mina

When lives are gone, and you go to the first layout, prior to that try:

System - Reset Global variables

which should reset to their initial values.

Alternatively, specifically initialize your variables on the first layout - that way, they will always have the correct values on start of game.

Is that what you mean?

If not, please explain what you expect or want to happen, or post a .capx.zenox982011-12-07 18:58:46
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,844
Reputation: 48,289

Post » Wed Dec 07, 2011 7:02 pm

@ zenox98

Thanks 4 ur quick reply, but what if i want to go to the next level not to the end or the start of the of the same layout?

I don't want to reset the global variables, i want them to continue if i want to go to the next level and to reset if i want to go to the start of the same level.

How can i do that?
B
303
S
6
G
5
Posts: 163
Reputation: 12,152

Post » Wed Dec 07, 2011 7:09 pm

If you set your Globals to the values you want on the first layout - set score to zero, set lives to 3, etc - then these will retain the values you give them for the life of the game, i.e. if you complete the level and go to the next layout, the Globals will still have the values they have attained during the game. They only get reset if you lose all your lives and start level 1 (first layout) again.

Is that what you mean?zenox982011-12-07 19:09:58
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,844
Reputation: 48,289

Post » Wed Dec 07, 2011 7:41 pm

Yes, that's exactly what i meant.

So where i need to add the reset global variables and how can i reset them?
B
303
S
6
G
5
Posts: 163
Reputation: 12,152

Post » Wed Dec 07, 2011 8:03 pm

Here's a screen shot from one of my games.



As you can see, I have an initialize group in my first level (after the menu) that sets everything up. This only happens on level 1, when the game first starts. After that, the values stored in the Global Values will be retained across all subsequent levels.

If your game is losing the values or the Globals are getting mashed somehow, then we really need to see your event to work out why.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
120
S
28
G
68
Posts: 4,844
Reputation: 48,289

Post » Thu Dec 08, 2011 7:44 pm

here is the capx file

http://dl.dropbox.com/u/52040403/livesandscores.capx
B
303
S
6
G
5
Posts: 163
Reputation: 12,152

Post » Thu Dec 08, 2011 7:49 pm

If you need to reset a variable, just do something like this:

system -- set value -- var -- set to 0
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Thu Dec 08, 2011 9:34 pm

minaPlatform.capx

Just cleaned things up and explain the Global variable concept in comment.
Last edited by Yann on Sun Sep 14, 2014 10:50 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Next

Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, abdalghani, Marxally, Naightwolf, pierre244 and 18 guests