• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

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

Stoozey

Member
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.
 

Stoozey

Member
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.
Thank you so much. Note to self to try to familiarize myself with built in components.
 
Top