• 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!

Sliding Door Issue

Zapzel-24

Member
Lately I have been having issues with implementing a sliding door mechanic I checked the code and it looked bulletproof but yet when put into practice it does not work.
in the Create_Event I added a variable "stop = false;." and a Alarm function that sets that sets the stop variable to true.

This is the Step_Event
GML:
if stop = false{
    y += 0.5
    alarm[0] = 30;
}else if stop = true {
    y += 0;
}
In Practice the door just simply continues to move down without stopping, leaving me confused, in theory when the alarm sets the stop variable to true and the door should stop.
 

Slyddar

Member
GML:
if stop = false{
  y += 0.5
  alarm[0] = 30;
} else if stop = true {
  y += 0;
}
A few things to assist with your logic.
If stop is not false, it has to be true, so your 2nd if check is redundant.
If you add 0 to y, does y change? It does not, so this line serves no purpose.
Lastly, while stop is false alarm[0] = 30. Every step stop is false, so every step alarm[0] is set to 30. The alarm will never go off with that logic. You need to set the alarm elsewhere in order for it to countdown, and turn it self off.

Alternatively you can do it like this:
GML:
if door_timer-- > 0 {
  y+= 0.5;
}
And just set door_timer to 30 elsewhere.
 
Top