Lock and Key code

Hi! One of the examples on the site is a key and lock game. There is a character that moves around. You need to pick up the key first, the character is now holding the key, and now that he has the key he can unlock the door.

I figured out that if I touch the “key” the character now changes to that frame inside my clip. And I know how to make the key disappear. But how can I make the LOCK only unlock with that specific character when he is holding the key.

Thanks

well make a clip with the character with the key i mean use a different walking animation with the key than use the hit code than on the door clip open so you will need to de if(this hits DoorClip ) {
DoorClip.gotoandstop(2)
}
well i hope i helped

1 Like

You can make a variable that’s connected to the project, and set it to true once the player picks up the key so the project knows if the player has the key or not.

For example:

In a default script, you can set “project.pickedUpKey” to false

project.pickedUpKey=false; // Key isn't picked up

When the player grabs the key, set it to true

project.pickedUpKey=true; // Key is picked up

Then, check if the key is picked up before opening the door

if(project.pickedUpKey===true){
// Code for opening door goes here
}else{
// Let the player know that they need the key
}
1 Like

heres a game I made at Key tutorial. I hope I helped.

1 Like

also welcome to the forums @Deidre_DuBose

1 Like

Thank you! It works fine when I play but when I look at Code Editor I have a couple lines highlighted in red like they are incorrect.

I have a couple of questions. I am new to WickEditor. I used Flash in college but hardly did any action script.

Key Code: Line 4: Why is it door.key. ?

Another question:

using && will allow you to multiple actions. I saw where you should use | instead.
Hope I’m making since.
I’m adding my document.LockKey.wick (4.1 KB)

If there is a line of code that has door.key that could mean
that in your wick project there is a clip object called door. Every
clip object has the ability to contain code itself. Probably inside the door
script, there is a property called key. You should see it like this.key from
the door script perspective… but from outside the door script itself, all other
scripts that want to reference that key property, must use door.key

(In summary, key is a property defined inside the door object, and you
can reference it or call it as door.key within the code)

Wick Editor uses javascript as a programming language. There are tons of javascript
tutorials in youtube that could help you to understand this concepts better.

How can make this Lock and Key project, when both doors are gone (unlocked) or TRUE then I can proceed to the next frame?
Lock_Key2.wick (5.3 KB)

My Project3-29-2021_15-08-14.wick (5.4 KB)

You can use && (&& means and in if statements and other things) and a variable that tells the frame if its unlocked.

The frame (as i said) will check if the two doors are locked, if they’re not, then use gotoNextFrame() to, well, go to the next frame.

Thank you!!!

1 Like

well you forgot to put Gotoandstop

My Project3-30-2021_16-25-26.wick (5.4 KB)

well its like the same thing because theres only two frames but ok thats better if you have more frames

but the next frame says you win

i think you win if you open the two doors o-o