• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Problem with doors

pixeltroid

Member
I just discovered this bug.

In my game, player uses a key to go past a door.

Heres the code that determines what happens if player collides with door:

Code:
if global.keys>0 {
with other{
global.door_opened[door_id] = true
instance_destroy();
audio_play_sound(sfx_dooropen,9,false)
instance_create(x,y,obj_dooropening)
 }
global.keys = global.keys -1 }
else {
speed = 0
}
And here's what I have in the doors creat

Code:
if global.door_opened[door_id] = true {
instance_destroy();
}
The code works...but ONLY if the door is NOT marked as a solid object. But, if its not marked as a solid object, the player can simply walk through the door even if he doesnt have a key!

However, if I mark the door as a solid object, the player cannot open it even if he has a key!

What am I doing wrong?

Any help would be appreciated!
 
N

NeZvers

Guest
Well, of course, that's why you should use your own collision "event" in the step event. Collision event is triggered when you collide with other objects.
You simply need to check place_meeting(x+sign(horizontal_speed), y, obj_door) and if it's true use instance_place(x+sign(horizontal_speed), y, obj_door) to get id for with().
 

pixeltroid

Member
Well, of course, that's why you should use your own collision "event" in the step event. Collision event is triggered when you collide with other objects.
You simply need to check place_meeting(x+sign(horizontal_speed), y, obj_door) and if it's true use instance_place(x+sign(horizontal_speed), y, obj_door) to get id for with().
I'm not sure I follow :/

Could you post the exact code for my objects?
 
N

NeZvers

Guest
something like this
Code:
if(place_meeting(x+sign(horizontal_speed), y, obj_door))
{
    var door = instance_place(x+sign(horizontal_speed), y, obj_door); //save ID
    global.door_opened[door] = true;
    instance_destroy(door);
    audio_play_sound(sfx_dooropen,9,false)
    instance_create(x,y,obj_dooropening)
}
 

pixeltroid

Member
something like this
Code:
if(place_meeting(x+sign(horizontal_speed), y, obj_door))
{
    var door = instance_place(x+sign(horizontal_speed), y, obj_door); //save ID
    global.door_opened[door] = true;
    instance_destroy(door);
    audio_play_sound(sfx_dooropen,9,false)
    instance_create(x,y,obj_dooropening)
}
Hi.

I got this error:


Variable obj_player.horizontal_speed(100063, -2147483648) not set before reading it.
at gml_Object_obj_player_StepNormalEvent_8 (line 2) - if(place_meeting(x+sign(horizontal_speed), y, obj_door))
What should I store "horizontal_speed" to?
 
N

NeZvers

Guest
Your movement speed. If it's top-down then same for y.
horizontal_speed was just placeholder name you have to figure out what to put there.
You can use a variable like hinput = right_key - left_key;
Basically, you need to check if there's a collision one pixel in front same as you would check for a floor in a platformer, only you get ID to manipulate door.
 
Last edited:
Top