[SOLVED] How do I efficiently change levels?

0 favourites
  • 5 posts
From the Asset Store
Unlock Levels, Worlds & skin plus add coins by watching ads
  • What's an efficient way to change levels?

    In my game I plan to have 100 levels. So far I have designed 22 levels.

    Before the player goes to the next level, they will see a score screen for the level they just completed.

    I have hardcoded checking a global variable that stores the name of the level they were just on, and then going to the next layout.

    But when you plan to put in 100 levels, having 100 lines of code just specifying the layout to go to makes me feel yuck and I'm convinced there's an easier way to do this.

    I thought that perhaps I could change the levels to just numbers and then set an increment the numbers where needed but the problem is I cannot "go to layout (by name)" just by setting the value to my global variable number that keeps track of what level the player is on. It has to be a string.

    What's the best way to do this where I don't have to put 100 lines of "system g_Level = "Level_<levelnumber>" - System Go to Level_<levelnumber>?


  • It's in format : go to layout by name "level "&variable, so becomes level 1, level 2 etc

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Plinkie. That made a lot more sense.

    I just have one more question then - How do I keep the variable updated then?

    For example my levels go like this - "Level_<number>" How can I just set the variable g_level which is a number variable to the number after the _ in the layout name?

    First of all I would need to check to see if the player is on a layout starting with "Level_" then if so, set it to the number after the underscore. I'm hoping to have a condition that checks this as an expression and then have an action that would set the variable to the number after _ - but I don't know how to do that.

  • Make sure your g_level is a global variable, and starts at whatever number your first level ends with. (ex. Level_0)

    On your win condition:

  • Thanks FromChris. I decided to do that anyway. I just thought there would have been a different way to do it. There doesn't appear to be any system condition that checks what layout the game is on. You have to track that with a variable then check it.

    Appreciate the help from both of you, thank you!

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