There's some functions in GE just for getting key states in scripts. The one you'll most likely need is called
GetKeyState()For jumping, though, it'll repeat every frame, so in this example, make a variable using Game-Editor's GUI that's called
jumping and is set to an
actor variable, then place code like this in your actor's
draw actor event:
- Code: Select all
// This sets our variable, we use this to check
// which keys are active.
char* key = GetKeyState();
// And now we start checking our variable.
// the "&& jumping" makes sure this only happens
// if keydown for SPACE is YES and jumping is NO
// so it doesn't keep repeating.
if(key[KEY_SPACE] == 1 && jumping == 0) {
yvelocity = -8;
jumping = 1;
}
In this case, you'll also want to make another event on this actor, where collision with the top of the ground sets jumping to 0, so you can jump again.
You can make as many IF statements as you want, of course, using most of the keys on the keyboard. This here is the list of all the keys that you can use like in the above example:
- Code: Select all
KEY_BACKSPACE
KEY_TAB
KEY_CLEAR
KEY_RETURN
KEY_PAUSE
KEY_ESCAPE
KEY_SPACE
KEY_EXCLAIM
KEY_QUOTEDBL
KEY_HASH
KEY_DOLLAR
KEY_AMPERSAND
KEY_QUOTE
KEY_LEFTPAREN
KEY_RIGHTPAREN
KEY_ASTERISK
KEY_PLUS
KEY_COMMA
KEY_MINUS
KEY_PERIOD
KEY_SLASH
KEY_0
KEY_1
KEY_2
KEY_3
KEY_4
KEY_5
KEY_6
KEY_7
KEY_8
KEY_9
KEY_COLON
KEY_SEMICOLON
KEY_LESS
KEY_EQUALS
KEY_GREATER
KEY_QUESTION
KEY_AT
KEY_LEFTBRACKET
KEY_BACKSLASH
KEY_RIGHTBRACKET
KEY_CARET
KEY_UNDERSCORE
KEY_BACKQUOTE
KEY_a
KEY_b
KEY_c
KEY_d
KEY_e
KEY_f
KEY_g
KEY_h
KEY_i
KEY_j
KEY_k
KEY_l
KEY_m
KEY_n
KEY_o
KEY_p
KEY_q
KEY_r
KEY_s
KEY_t
KEY_u
KEY_v
KEY_w
KEY_x
KEY_y
KEY_z
KEY_PAD_0
KEY_PAD_1
KEY_PAD_2
KEY_PAD_3
KEY_PAD_4
KEY_PAD_5
KEY_PAD_6
KEY_PAD_7
KE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