• 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!

Error Unknown variable j please help, thank you

Error:
Code:
___________________________________________
ERROR in
action number 1
of  Step Event
for object Carl:

Error in code at line 63:
       if (instance_exists(j))

at position 26: Unknown variable j



About Carl:
Code:
Information about object: Carl

Sprite: Carl_Sprite
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>

 Step Event:
execute code:

if (keyboard_check_pressed(ord("J")))
{
  x = xstart;
  y = ystart;
}
if (keyboard_check(vk_up))
{
  vspeed = -2;
}
if (keyboard_check(vk_right))
{
  hspeed = 2;
}
if (keyboard_check(vk_left))
{
  hspeed = -2;
}
if (keyboard_check(vk_down))
{
  vspeed = 2;
}
if (keyboard_check_released(vk_down))
{
  vspeed = 0;
}
if (keyboard_check_released(vk_left))
{
  hspeed = 0;
}
if (keyboard_check_released(vk_right))
{
  hspeed = 0;
}
if (keyboard_check_released(vk_up))
{
  vspeed = 0;
}
if (instance_exists(Vertical_Moving))
{
  if (place_meeting(x,y+2,Vertical_Moving))
  {
    var j;
    j = instance_place(x,y+2,Vertical_Moving);
    if (instance_exists(j))
    {
      while(j)
      {
        j = instance_place(x,y+2,Vertical_Moving);
        vspeed = 0;
        direction = j.direction;
        speed = j.speed;
        break;
      }
    }
  }
}
if (instance_exists(Horizontal_Moving))
{
  if (place_meeting(x,y+2,Horizontal_Moving))
  {
    var k;
    k = instance_place(x,y+2,Horizontal_Moving);
    if (instance_exists(j))
    {
      while(k)
      {
        k = instance_place(x,y+2,Horizontal_Moving);
        vspeed = 0;
        direction = j.direction;
        speed = j.speed;
        break;
      }
    }
  }
}


About Horizontal_Moving
Code:
Information about object: Horizontal_Moving

Sprite: Horizontal_Moving_Sprite
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>

Create Event:
execute code:

alarm[0] = room_speed*3;
direction = 360;
speed = 2;

Alarm Event for alarm 0:
execute code:

direction = 180;
speed = 2;
alarm[1] = room_speed*3;

Alarm Event for alarm 1:
execute code:

direction = 360;
speed = 2;
alarm[0] = room_speed*3;


About Vertical_Moving
Code:
Information about object: Vertical_Moving

Sprite: Vertical_Moving_Sprite
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: <no parent>
Mask: <same as sprite>

Create Event:
execute code:

direction = 90;
speed = 2;
alarm[0] = room_speed*3;

Alarm Event for alarm 0:
execute code:

direction = 270;
speed = 2;
alarm[1] = room_speed*3;

Alarm Event for alarm 1:
execute code:

direction = 90;
speed = 2;
alarm[0] = room_speed*3;
 
Bruh, look at your code block for the Horizontal_Moving check. You mix "j" and "k" throughout it.


I'm also a bit confused by what you're trying to do. Wouldn't it be simpler to just use the initial check?
Code:
var k = place_meeting(x,y+2,Horizontal_Moving);
if (k)
{
    vspeed    = 0;
    direction = k.direction;
    speed     = k.speed;
}
 
Top