Reputation: 11
I'm making a game in which you have to pick up a key first with your character and then go to the door. When you hit the door, you should go to the next frame. Without the key, you can't pass the door. You should pick up the key with hitTestObject and go to the next frame with hitTestObject too.
Could someone help me? Thanks!
Here is my code:
var gotKey:Boolean = false;
if(Jack.hitTestObject (unlock))
{
unlock.visible = false;
gotKey == true;
trace ("You got the key!")
}
if (Jack.hitTestObject (house))
{
if (gotKey == true)
nextFrame();
trace ("level achieved")
}
Upvotes: 0
Views: 1796
Reputation: 7722
I guess you wanted to assign the variable gotKey to true (=), instead of comparing it to true (==)
if(Jack.hitTestObject (unlock))
{
unlock.visible = false;
gotKey == true;
trace ("You got the key!")
}
should be:
if(Jack.hitTestObject (unlock))
{
unlock.visible = false;
gotKey = true;
trace ("You got the key!")
}
Upvotes: 1
Reputation: 121
Are you getting a compile error, or are you looking for help with the logic? Because what you've got should work, but you've left out a set of curly braces on the gotKey logic check where Jack hitTestObjects house.
if (Jack.hitTestObject (house))
{
if (gotKey == true)
nextFrame();
trace ("level achieved")
}
should be
if (Jack.hitTestObject (house))
{
if (gotKey == true) {
nextFrame();
trace ("level achieved")
}
}
Upvotes: 0