Different keys for different doors

Get help using Construct 2

Post » Mon Dec 23, 2013 5:38 pm

Hello everyone!

I have a simple game where I have different doors, so only one kind of key should open those doors.

For start I have two kinds of keys, blues and reds. But I'm having trouble figuring out how I make the blue keys open only the blue doors and the red keys open only the red doors. Right now both keys are opening both doors.

Can anyone take a look? Here is my .capx file: https://dl.dropboxusercontent.com/u/8017129/C2%20Forum%20Files/keys-and-doors.capx

almeidamarcell2013-12-23 17:39:29
B
16
S
4
G
4
Posts: 56
Reputation: 2,942

Post » Mon Dec 23, 2013 5:50 pm

Use an instance variable
B
9
S
3
G
1
Posts: 112
Reputation: 1,827

Post » Mon Dec 23, 2013 7:18 pm

I still don't know much about arrays in construct, but it seems that the game doesn't know if the key is red or blue. It seems that it only identifies it as a key, regardless of the color. (I understood almost nothing in your file. I don't know if that's my lack of experience in using arrays in Construct 2 or lack of organization of your part)

I don't know how to do it in inventory using an array, but I'll do something like this:

Create a red key and blue key sprite

Create a variable inside these sprites that holds a value of how many was found (redKeyQuantity = 0)

If player collides with red key, adds a number to redKeyQuantity. Same with blue key, adding to blueKeyQuantity.

When player collides with a red door, check to see if redKeyQuantity is greater than 0. If yes, open door and subtracts 1 from redKeyQuantity. If not, don't let the player pass! The same for blue.

Well, that is the way I would do it. I don't know how to do it with an inventory array, but I guess the logic is the same. Maybe there's a more efficient way to do it, but I think this way is very easy to understand and not difficult to modify later if you need.Martiny2013-12-23 19:19:50
B
7
S
1
Posts: 15
Reputation: 589

Post » Tue Dec 24, 2013 8:20 am

Well, me thinks this is what you're after. Do note I modified pretty much all of the code and removed unneeded items. The doors do not prevent you from crossing them, if you have no key, as I figure you can add such a simple lot of code.

Hope you enjoy - https://dl.dropboxusercontent.com/u/108799982/Capx%20Demos/DoorsAndKeys.capxemoaeden2013-12-24 08:21:25
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699

Post » Tue Dec 24, 2013 5:28 pm

[QUOTE=emoaeden] Well, me thinks this is what you're after. Do note I modified pretty much all of the code and removed unneeded items. The doors do not prevent you from crossing them, if you have no key, as I figure you can add such a simple lot of code.

Hope you enjoy - https://dl.dropboxusercontent.com/u/108799982/Capx%20Demos/DoorsAndKeys.capx[/QUOTE]

Thank you so much emoaeden! I really don't know how to thank you for that. It really helped me and it's well done, very well done. It's a lesson learned! Thank you again!
B
16
S
4
G
4
Posts: 56
Reputation: 2,942

Post » Tue Dec 24, 2013 8:04 pm

Anytime mate, maybe one day you can do the same:for ithers on here :-)
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 34 guests