1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 8:30 to 11:30 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

Gml movement with WASD

Discussion in 'Programming' started by Montigor, Mar 9, 2017.

Tags:
  1. Montigor

    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.
     
  2. anthropus

    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.
     
  3. Montigor

    Montigor Guest

    Thank you very much for your help :) It works now.
     
    anthropus likes this.

Share This Page