lives and scores

0 favourites
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Please, upload your capx file. It will help us to understand what is happening :)

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

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

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

  • Yes, that's exactly what i meant.

    So where i need to add the reset global variables and how can i reset them?

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

    <img src="http://dl.dropbox.com/u/34306693/initgame.png" border="0" />

    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.

  • here is the capx file

    dl.dropbox.com/u/52040403/livesandscores.capx

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

    system -- set value -- var -- set to 0

  • minaPlatform.capx

    Just cleaned things up and explain the Global variable concept in comment.

  • Yann

    Mina's problem is that after playing through the level, it shows the Start page again, but on Pressing Enter to start, the text boxes are missing.

    It can be quickly fixed by setting the text boxes 'Global Property' to 'No', although the values will no longer display on the Start page after completing the level, which I'm not sure is how Mina wants it.

  • Oh! well it's not really a problem is it?

    You just have to duplicate the object and change its text with event as you still have the value in the global variables.

    minaPlatform.capx

  • You're correct in that it is easy to fix, but I wanted to know WHY the text objects and sprite didn't appear.

    After adding some debug code, it seems that on start of Layout 1, these global objects are on Layer 3, but after level is completed, they move to Layer 0 (because there is no layer 3 on the subsequent layout), which means that when you press Enter to start again, these objects are still on Layer 0 so don't show.

    It seems logical, but I would have thought it would have reset the layer back to 3 on this layout, which it doesn't. You can always specifically set these objects to the correct layer on Start of Layout using 'move to layer' but it's still seems wrong to me.

    Personally, I just think the use of global objects is ambiguous, and not readily understandable to the layman. Users are probably expecting these global objects to appear on all layouts, which without extra coding, they won't.

    Sorry for the waffling, people :/

  • How it was used in Mina's capx is not a proper use of global object. Global object shouldn't even be used for Graphical representation.

    The only things that should be global are data you want to keep through layouts (score/lives/position/etc)

    I used to use Global object in cc to avoid updating sprites in each layout each time I change things.

    But now Sprite instance even if not global share the same Object Definition in the Object library (Texture, variables, behavior, etc). So if you want to change animation or instance variable definition for the whole project, you can change on the instance and it will be changed for all layout even if it's not global.

    I can't really figure out why making graphical element global.

  • Yann

    Exactly my point!

    It's all about user expectation - what does the user expect to happen.

    As you have said, why are objects allowed to be global? One for Ashley, I feel.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)