1. Hey! Guest! The 31st GMC Jam will take place between Nov 16th, 12:00 UTC (Friday noon) and Nov 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Question - Code Movement in only one direction? Others are syntax errors.

Discussion in 'GameMaker Studio 2 Community Tech Support' started by Stoozey, Nov 9, 2018.

  1. Stoozey

    Stoozey Member

    Joined:
    Nov 9, 2018
    Posts:
    2
    So, I am pretty new to GML and I decided to make a random little project for movement and changing sprites to go with it, and whenever I move using W/A/S I get a syntax error of this:
    Code:
    ___________________________________________
    ############################################################################################
    FATAL ERROR in
    action number 1
    of  Step Event0
    for object obj_sans:
    
    Unable to find any instance for object index '270' name '(null)'
     at gml_Object_obj_sans_Step_0 (line 44) -               direction.speed = walkSpeed;
    ############################################################################################
    --------------------------------------------------------------------------------------------
    stack frame is
    gml_Object_obj_sans_Step_0 (line 44)
    
    The error above is me pressing the S key. Something I am finding strange is that when I press the D key, everything is fine and the character will move.

    Here is the code, (any advice on making my code neater would also be appreciated but I mainly just need help with this ;) )
    Code:
    if(canMove = true){
        
        if keyboard_check(ord("W"))
       {
            
            sprite_index = spr_sans_u;
            
            isWalking = true;
            direction = 90;
            direction.speed = walkSpeed;
       }
      
           else if keyboard_check(ord("D"))
       {
        
            sprite_index = spr_sans_r;
            
            isWalking = true;
            direction = 0;
            direction.speed = walkSpeed;
       }
      
           else if keyboard_check(ord("A"))
       {
            
            sprite_index = spr_sans_l;
            
            isWalking = true;
            direction = 180;
            direction.speed = walkSpeed;
       }
      
           else if keyboard_check(ord("S"))
       {
            
            sprite_index = spr_sans_d;
            
            isWalking = true;
            direction = 270;
            direction.speed = walkSpeed;
       }
    }
    else
    {
        isWalking = false;
    }
    
    
    P.S - very sorry if the resolution is very obvious, I'm trying to make a better transition into GML.
     
  2. BaBiA Game Studio

    BaBiA Game Studio Member

    Joined:
    Jun 20, 2016
    Posts:
    576
    direction is a built-in variable, not an object, but you are trying to use it like an object. Surely you just want to do:
    Code:
    speed = walkSpeed;
    As speed is also a built-in variable.
     
  3. Stoozey

    Stoozey Member

    Joined:
    Nov 9, 2018
    Posts:
    2
    Thank you so much. Note to self to try to familiarize myself with built in components.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice