Jump to content


Photo

Door problem


  • Please log in to reply
10 replies to this topic

#1 seanpk21

seanpk21

    GMC Member

  • New Member
  • 57 posts

Posted 09 September 2011 - 02:49 AM

So I want my door to open whenever it collides with the player, assuming he has at least one key. And then one key gets subtracted from the total.
However, if he doesn't have any keys, he cannot pass through it.

if global.keys > 0 
{
oDoor.solid = false;
sound_play(door_open);
instance_destroy();
}
else
{
global.keys = 0
oDoor.solid = true;
}

Except when I hit the door first, and THEN grab the key, then try again, it doesn't work. But if I get the key first, then it opens.
How do I fix this?

Edited by seanpk21, 09 September 2011 - 02:50 AM.

  • 0

#2 angryfrodo

angryfrodo

    GMC Member

  • New Member
  • 54 posts

Posted 09 September 2011 - 03:08 AM

if global.keys >= 1
{
oDoor.solid = false;
sound_play(door_open);
instance_destroy();
}
else
{
global.keys = oDoor.solid = true;
global.keys -= 1;
}

I think that should probably do it.

Edited by angryfrodo, 09 September 2011 - 03:09 AM.

  • 0

#3 seanpk21

seanpk21

    GMC Member

  • New Member
  • 57 posts

Posted 09 September 2011 - 03:11 AM

if global.keys >= 1
{
oDoor.solid = false;
sound_play(door_open);
instance_destroy();
}
else
{
global.keys = oDoor.solid = true;
global.keys -= 1;
}

I think that should probably do it.


Nope, he just passes through it both times. With and without the key.
  • 0

#4 angryfrodo

angryfrodo

    GMC Member

  • New Member
  • 54 posts

Posted 09 September 2011 - 03:12 AM


if global.keys >= 1
{
oDoor.solid = false;
sound_play(door_open);
instance_destroy();
}
else
{
global.keys = oDoor.solid = true;
global.keys -= 1;
}

I think that should probably do it.


Nope, he just passes through it both times. With and without the key.



Hmmm okay, lemme think. So if he doesn't have a key, and then you go and grab the key, the door won't open. Do you have something that says when you pick up the key that global.keys += 1?
  • 0

#5 angryfrodo

angryfrodo

    GMC Member

  • New Member
  • 54 posts

Posted 09 September 2011 - 03:16 AM

if global.keys >=1
{
oDoor.solid = false;
sound_play(door_open);
instance_destroy();
global.keys -= 1;
}
else if global.keys <= 0
{
oDoor.solid = true;
}


in the game start event set global.keys = 0;
  • 0

#6 seanpk21

seanpk21

    GMC Member

  • New Member
  • 57 posts

Posted 09 September 2011 - 03:27 AM

if global.keys >=1
{
oDoor.solid = false;
sound_play(door_open);
instance_destroy();
global.keys -= 1;
}
else if global.keys <= 0
{
oDoor.solid = true;
}


in the game start event set global.keys = 0;


Nope, if I touch the door, get the key and then touch the door again, it doesn't open.
  • 0

#7 sneaky666

sneaky666

    536e65616b79

  • GMC Member
  • 1034 posts
  • Version:GM8

Posted 09 September 2011 - 03:32 AM

So I want my door to open whenever it collides with the player, assuming he has at least one key. And then one key gets subtracted from the total.
However, if he doesn't have any keys, he cannot pass through it.

if global.keys > 0 
{
oDoor.solid = false;
sound_play(door_open);
instance_destroy();
}
else
{
global.keys = 0
oDoor.solid = true;
}

Except when I hit the door first, and THEN grab the key, then try again, it doesn't work. But if I get the key first, then it opens.
How do I fix this?


which object is this code in?
and can u explain whats the purpose of this code?

Edited by sneaky666, 09 September 2011 - 03:32 AM.

  • 0

#8 seanpk21

seanpk21

    GMC Member

  • New Member
  • 57 posts

Posted 09 September 2011 - 03:38 AM


So I want my door to open whenever it collides with the player, assuming he has at least one key. And then one key gets subtracted from the total.
However, if he doesn't have any keys, he cannot pass through it.

if global.keys > 0 
{
oDoor.solid = false;
sound_play(door_open);
instance_destroy();
}
else
{
global.keys = 0
oDoor.solid = true;
}

Except when I hit the door first, and THEN grab the key, then try again, it doesn't work. But if I get the key first, then it opens.
How do I fix this?


which object is this code in?
and can u explain whats the purpose of this code?



The object is in the door object.

I want my door to open whenever it collides with the player, assuming he has at least one key. And then one key gets subtracted from the total.
However, if he doesn't have any keys, he cannot pass through it.


  • 0

#9 sneaky666

sneaky666

    536e65616b79

  • GMC Member
  • 1034 posts
  • Version:GM8

Posted 09 September 2011 - 05:05 AM

so if you touch a door, if your keys is more than 0, the door dies, and if you have 0 keys, then nothing happens?
If so why do you set its solid Boolean to false then destroy the door?

Edited by sneaky666, 09 September 2011 - 05:07 AM.

  • 0

#10 seanpk21

seanpk21

    GMC Member

  • New Member
  • 57 posts

Posted 09 September 2011 - 05:38 AM

I solved it!

I had to put
oDoorDouble.solid = true;
in the creation event

and
if global.keys >=1
{
oDoorDouble.solid = false;
}
else if global.keys <= 0
{
global.keys = 0;
}

in the Step event.
  • 0

#11 sneaky666

sneaky666

    536e65616b79

  • GMC Member
  • 1034 posts
  • Version:GM8

Posted 09 September 2011 - 01:42 PM

why do you need this part
else if global.keys <= 0
{
global.keys = 0;
}
?
will global.keys ever be less than 0?
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users