Keys and Doors

For questions about using Classic.

Post » Sun Mar 22, 2009 4:43 pm

Guys i need your help.
i have 3 objects. a) The playr character. b) a door. c) a door key. I wan my character to reach the next level [u:2z3lzfgw]only[/u:2z3lzfgw] if he holds the key! I think that the right way to do it is to use a variable, assign a value and when the character picks up the key subtract a value form the variable. How can i achieve this? It looks easy but somehow i can't do it :?
B
2
G
4
Posts: 29
Reputation: 1,108

Post » Sun Mar 22, 2009 4:50 pm

First, you have a private variable named HasKey. Default value would be 0.
Second, when he picks the key up, add 1 to the value.

+Player is overlapping Door
+Player('HasKey')=1
>Next Layout

Basically, you want both conditions in the same event; when he is at the door, check if he has the key and allow him passage if he does.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Mar 22, 2009 5:03 pm

So i created a new event with Player is overlapping Door but i cant exactly understand the following:
+Player('HasKey')=1
I'm confused :?
B
2
G
4
Posts: 29
Reputation: 1,108

Post » Sun Mar 22, 2009 5:14 pm

It's a private variable. Try the ghost shooter tutorial. It tells you about them.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Mar 22, 2009 10:14 pm

I still don't get it! U can laugh at me now :oops:
here is the link. Can any kind soul help me?
[url:3qqf693j]http://www.mediafire.com/download.php?xomyd0tjhw2[/url:3qqf693j]
B
2
G
4
Posts: 29
Reputation: 1,108

Post » Mon Mar 23, 2009 12:28 am

Nobody is laughing mate, but it does look like you need to do some of the tutorials to get you up to speed on the way Construct works.

As for your problem, you've added an extra instruction that sets the variable rather than adding an extra condition.

Delete the statement that sets your variable in line 5, and then right-click the condition and select "insert new condition", as illustrated below:



It should then look like this:



Now you'll need to delete the first 3 lines in your program.
I don't know what you were trying to do there, but they don't have any conditions.
You also appear to have some blocks hidden on layer 2, and I had to move one of them before I could get to the door when I ran it.

Your next stop should really be the wiki and the many tutorials available.
You'll soon get the idea.

Sponge.
B
2
S
1
G
3
Posts: 105
Reputation: 1,310

Post » Mon Mar 23, 2009 9:32 am

Cheers SpongeBrain :D
B
2
G
4
Posts: 29
Reputation: 1,108

Post » Tue Mar 24, 2009 12:08 am

I run into another problem and no matter what i do i can't solved it.
When i pick up the key and the player overlaps with the door the game moves to the next layout, so far so good.However, if i don't pick up the key the player passes through the door. Upon setting the door properties to solid even if i have the key i cant move to the next level!
I've read the tutorials but i'm still confused. Construct's way of doing things is so different from Gamemaker. It's not a bad thing, just a little bit confusing!
B
2
G
4
Posts: 29
Reputation: 1,108

Post » Tue Mar 24, 2009 12:36 am

I'm actually a little confused but I think I get what you mean.

So if the player is overlapping the door and has the key, the game will instantly jump to the next layout, right?! Just put an invisible sprite that checks for overlap and the HasKey variable in front of the visible door, which can be solid now of course. That way you can get an overlap.

Even easier: you could check for overlap at offset.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Tue Mar 24, 2009 3:09 am

Why are you setting the door to sollid in the first place? Solid objects are unpassable, period. You will never overlap with them. At least, not if you're using a built-in behavior like Platform or 8 Direction.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests