Restarting level in a puzzle game

0 favourites
  • 11 posts
From the Asset Store
An amazing and interesting puzzle game for kids!
  • Hi there,

    I have a problem with my very first game with C2. It's a puzzle game and you have to make disappear the cubes on the screen.

    In every level I added an object that acts like a button that should restart the layout when clicked if you did it wrong. The problem is that when you click on restart, it does, yes, but inmediately changes to the next layout as if level was finished and I don't know why.

    I have a global variable called "cubes_level_01" = 3. And there's an event that leads you to next level:

    EVENT:

    System - "cubes_level_01" (less or equal to) 0

    ACTIONS:

    System - Wait 2.0 seconds

    System - Go to "level_01_finished" (name of next layout)

    If you play, game runs correctly. But if you try at any moment the restart button, it leads you to the next layout. The event for reset is:

    EVENT:

    Mouse - On left button clicked on "reset_button"

    ACTIONS:

    System - Restart layout

    System - Reset global variables to default

    I suppose that the problem is that when you reset level, "cubes_level_01" variable turns automaticaly to zero. It's the only explanation, but I can't find why. Can you help me, please?

    Thanks in advance.

  • "System - Reset global variables to default"

    default is always zero, have and event that goes

    "System - "cubes_level_01" (less or equal to) 0"

    so when it resets the variables to default it also sets the "cubes_level_01" to 0 so they would have the same effect as completing the level,

  • Thanks, Backlog, for the answer.

    I deleted "reset global variables to default" and changed it into "set "cubes_level_01" to 3 (the initial value of the variable)", but the problem persists.

  • I would need to see more of your code sheet.

    post a capx or take a screen shot of your event sheet showing as much of the event sheet as possible

  • I don't know much about this. How can I share with you the capx?

    I put it in Google Drive:

    docs.google.com/file/d/0B4iQP7YxdOIRWDdCYXlTbjNjcFk/edit

    Don't be cruel. It's my first game, and I'm pretty sure the game logic can be made much better (but I don't know how).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Any suggestions?

  • I think I got a solution, I added a "On Start of Layout" Event at the top, and added the "cubes_level_01=3" there.

  • Fixed for you. Set Global Number cubes_level_01 to be Constant (checkbox when double click it)

  • Thanks very much, Paradox and Plinkie. I wouldn't have discovered it by myself.

  • Actually the above won't work for your game. Sorry, do this :

    On left button clicked on reset button > Restart layout, reset global variables to default.

  • the issue was on the restart of the layout all of your blocks were being destroyed and that would make the cubes_level_01 counter drop to -10 on restart of the layout.

    so having a reset global variables like plinkie said or doing like paradox said and adding a "on start of layout > set cubes_level_01 to 3" (this is the way I also solved the problem when i tried before looking at the thread) the game resets the value to 3 on restart rather then following the code and leaving it at a -10 value.

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