Alarm Cancelling

S

Skyler Clark

Guest
Hey everyone, so the game I’m trying to make is pretty simple. The player is a ghost and has to possess all of the humans in the room before it can move on. I want it to where the player has to hold down F for 3 seconds while making contact with the human before the human is possessed. Right now I’m only changing the image index for the human when it is possessed.

Now here is where I need help. I want it so that if the player lets go of the F key before te human is possessed, the alarm stops and resets, so when the player goes back and tries to possess the human again, they have to wait 3 seconds again. So basically if they leave and come back I don’t want the human to already be partly possessed. I don’t want the alarm to pause, I want it to reset and not do the effects. I know it’s kind of complicated, sorry. Any help would be greatly appreciated. Thanks!
 
S

Skyler Clark

Guest
Setting an alarm to -1 turns it off without triggering it.
I made a variable and set it to false, and I made it so when the alarm goes off, the variable is changed to true. I tried to set the alarm to -1 if the F key was not pressed and the variable was false. Is this how I would do it? If I need to include the code I will.
 

TheouAegis

Member
I'd do it on the F key released event if you're using events, or keyboard_check_released(ord("F")) if you're using the Step event. Not sure you'd need to check if the variable was false, since right now you're only using the alarm for that one thing anyway.
 
T

Timze

Guest
my 2 cents
pseudo code / general idea:
/// collision event

if obj_ghost is colliding with obj_human && F key is held
alarm -1;
if obj_ghost is colliding with obj_human && F key is held && alarm <= 0
{ possess player;
alarm = 3; // 180
}

if obj_ghost is colliding with obj_human && F key is released && alarm is > 0
alarm = 3.
 
Top