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

keyboard_check in a step event

T

tech9151

Guest
Hi,

I just started using game maker again and am trying to make a basic project to visualize an idea of mine. I seem to be having trouble with a code already as I thought we could use the keyboard_check in the step event? Seems to not work at all. I tested to see if I used the Keyboard Event itself if it would work and it did. If someone can let me know if it is possible to use keyboard_check in step event or if I should just use the keyboard event.

Thanks, code below, variable is key_enter that I am trying to get to work.

Create Event:
Code:
MP = 0;
GP = 0;
turn = false;


sel_on = false;
num = 0;
num_max = 2;
sel[0] = "Base";
sel[1] = "Attack Unit";
sel[2] = "Defense Unit";

key_enter = keyboard_check_released(vk_enter);
key_l = keyboard_check(vk_left);
key_r = keyboard_check(vk_right);

Step Event:
Code:
if key_enter
    sel_on = true;
if sel_on
    {
        if key_l
            {
            num -= 1;
            if num < 0 num = num_max;
            }
        if key_r
            {
            num +=1 ;       
            if num > num_max num = 0;
            }
    }
 
I thought we could use the keyboard_check in the step event?
You can. But you aren't. You are calling keyboard_check and keyboard_check_released in the Create Event. That means that only as the object is created will it check if you have pressed the keys. You need to take these lines out of your Create Event:
Code:
key_enter = keyboard_check_released(vk_enter);
key_l = keyboard_check(vk_left);
key_r = keyboard_check(vk_right);
and put them into the top of your Step Event. Put them above all the other code you already have in your Step Event. Then it should all work fine.
 
Top