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

Get help using Construct 2

Post » Mon Jul 07, 2014 11:23 am

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 :D

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?
B
9
S
1
Posts: 97
Reputation: 715

Post » Mon Jul 07, 2014 12:19 pm

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.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Jul 07, 2014 2:35 pm

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!
B
9
S
1
Posts: 97
Reputation: 715

Post » Mon Jul 07, 2014 2:45 pm

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.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests