Is there a way to have an event only run the first time a certain layout is started?

0 favourites
  • 3 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • I'm working on adding a level select to my game, and I want to make it so you can't play a level from the level select until you've completed it. I want to make the level's icon in the level select disappear when it's locked. Is there a way to make the unlock event so it only runs the first time you play the level?

  • There's a lot of different ways to achieve this, depending on your game's needs.

    To mark a level as completed, a simple way would be to create a series of global variables in your event sheet. These would be booleans, called "Level1Complete", "Level2Complete", etc. Because they're global variables, they'll retain their data from layout to layout.

    You could also create a Dictionary object, with keys named that way, and set to either 0 or 1. If there's going to be more information about each level you want to store, consider an Array instead of a Dictionary.

    However you choose to store these flags, you'll need to add a system condition called "On Start of Layout" in the event sheet for the level select. This only runs once, and it's useful setting things up before the user has control or sees anything.

    Now you can add sub-events to your On Start of Layout condition. Using the simple global booleans, you can add events to each one to see if it's true, then unlock the level if so (such as "If Level1Complete is True, destroy LevelIcon"). If you use a Dictionary or Array, you can do the same (and more) in a more elegant way.

    Hope that helps!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not a very good coder, so I would use some cheesy workarounds.

    First I'd make my "level select layout" with all the sprites exactly where I want them.

    Like brushfe said, set up a global boolean for each level.

    On start of layout, if LEVEL1 boolean is FALSE, move the level icon to a coordinate right outside of the layout where it can't be accessed.

    If it's TRUE, nothing happens and the icon stays exactly where it is.

    In my game, if sprite is overlapping LEVEL1ICON and spacebar is pressed, start Level 1. If the icon is off screen and inaccessible, that condition can't be met.

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