Gml movement with WASD

M

Montigor

Guest
Hi, i am very new to Gamemaker and many hours trying to make object move with W A S D keys but can not do that. I tried to take code from other users but it did not help.

if (keyboard_check(ord('D'))) x = x + 4; // i tried this
i tried to write D with "" or with ' ' or without them.
if keyboard_check(ord('A')) {x = x + 4} // also tried this


I succeeded to launch game but got fatal error
FATAL ERROR in
action number 1
of Step Event0
for object obj_player:

Variable obj_player.D(100002, -2147483648) not set before reading it.
at gml_Object_obj_player_Step_0 (line 1) - if (keyboard_check(ord(D))) x = x + 4;

Thank you for your help.
 
A

anthropus

Guest
"Variable obj_player.D(100002, -2147483648) not set before reading it.
at gml_Object_obj_player_Step_0 (line 1) - if (keyboard_check(ord(D))) x = x + 4;"

ok here where it says at the end "if (keyboard_check(ord(D))) x = x + 4;" is the problem. there should be quotation marks around the D like this

if keyboard_check(ord("D"))
{
x=x+4;
}

i know you said you tried it with " " but try it again as in the code above, and if you get an error, post that error.

also, i recomend making a variable that contains the keyboard_check code.

in the object's create event write this:

D = keyboard_check(ord("D"))
spd=4

then you can write the code more easily like this

if (D)
{
x+=spd
}

also, check out some youtube tutorials, theres lots of beginner stuff that would help you a lot.
 
Top