DND - Reduce Var while key is pressed

G

Garling

Guest
I am trying to reduce a var while the Space is pressed, I have a var set to 100 and under the Space key pressed event I have it set to -10. It does reduce for each key press but I want it to reduce -10 for each 5 secs the key is pressed.
 

samspade

Member
I am trying to reduce a var while the Space is pressed, I have a var set to 100 and under the Space key pressed event I have it set to -10. It does reduce for each key press but I want it to reduce -10 for each 5 secs the key is pressed.
I don't work with DND but I can explain the logic. Two simple ways seem possible. First, you could reduce it by 10 / 300 per step (assuming 60 steps per second) so that it reduced a total of 10 over the course of 5 seconds. Second, you could set an alarm that will go off after 5 seconds if space is pressed and be reset if space is released. Again, I don't know what this would look like in drag and drop but in code it would look like this:

Code:
///step event
if (keyboard_check_pressed(vk_space)) {
    if (alarm[0] == -1) {
        alarm[0] = room_speed * 5;
    }
} else {
     alarm[0] = -1;
}


///alarm[0]
variable -= 10;
 
G

Garling

Guest
This is what I came up with
Code:
if (keyboard_check(vk_space))
{
    if(global.var_mag > 0)
    {
        y = y - 4;  
        global.var_mag -= .5
    }
}
 
Top