0 Favourites

How do I open doors to new levels based on a global variable

  • Hi!

    I'm trying to create a map-system from which the player enters new levels.

    My approach so far has been like this:

    -Create a global variable for storing the number of levels passed

    -Create doors on the map as instances of one door object

    -Give the doors a boolean instance variable called "unlocked" and set it to False by default.

    -Try to loop trough the doors and toggle the boolean if IID of a door is smaller than the global "levelsPassed" variable.

    The last part is giving me trouble (and I'm not even sure if my whole approach to this map is a good one).

    Here's what I tried for the loop:

    Condition 1: For each door order by door.IID ascending

    Condition 2: levelsPassed > door.IID

    Action: Set unlocked to True

    I'm still a newbie and that might be a very bad approach

    So in a nutshell, what would be a good way to loop trough my doors and toggle their instance variables based on the number of passed levels?

    EDIT:

    Turns out I was making a simple mistake and was setting the boolean to false instead of true. So this actually works!!

    I guess my only question would be that do you think this IID-dependency will give me trouble later on? Is there a smarter way to assign unique identifiers to the instances?

  • In addition to your unlocked variable have an instance variable 'doorLevel' (to replace how you're using IID at the moment). Assign whatever level you want each door to be. Then do Door: Compare instance variable doorLevel <= levelsPassed (or similar), and also the unlocked variable. You generally don't want to loop through IIDs like that. Also, you have to control somehow the order in which the doors are created. Sounds like the hard way.

  • Hi!

    Thanks for the reply!

    I was suspecting IID might not be the greatest solution.

    But I don't know what the right way to do the following is:

    "Assign whatever level you want each door to be."

    Should I do this assigning with a loop function or can it be done without any events?

    EDIT:

    To answer my own question it turns out instance variables can be changed directly in the editor for each instance separately. This certainly makes things a lot easier!

    Thanks for your help!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You got it. There are definitely times when using IID or UID is useful, but I don't think it's necessary in your case.

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