-1
var xpos = 0;
var ypos = 0; 
xpos = obj_magnet.x; 
ypos = obj_magnet.y;
if (xpos > 435 && xpos < 704 && ypos > 350 && ypos < 640)
{
    with(obj_lamp)
    {
        instance_change(obj_lamp_light, true);
    }
    if obj_lamp_light.image_index == 5
    {
        obj_lamp_light.image_speed = 0;
    }
    with(obj_arrow)
    {
        instance_change(obj_arrow_move_one_direction, true);
    }
    if obj_arrow_move_one_direction.image_index == 4
    {
        obj_arrow_move_one_direction.image_speed = 0;
    }
    with(obj_arrow_move_opposite_direction)
    {
        instance_change(obj_arrow, true);
    }
    exit;
}
else
{
    with(obj_lamp_light)
    {
        instance_change(obj_lamp, true);
    }
    with(obj_arrow_move_one_direction)
    {
        instance_change(obj_arrow_move_opposite_direction, true);
        if obj_arrow_move_opposite_direction.image_index == 4
        {
            obj_arrow_move_opposite_direction.image_speed = 0;
        }
    }
    exit;
}

This is a game which I am trying to create where the obj_arrow_move_opposite_direction and obj_arrow_move_one_direction contains 5 sub images and the obj_lamp_light contains 5 sub images.

Kake_Fisk
  • 1,107
  • 11
  • 22
shrouk
  • 43
  • 1
  • 1
  • 10

1 Answers1

0

You stated that each object contains 5 sub-images, correct? Looks like you're looking for a nonexistent sub-image (5) on line 7.

This appears to be a simple typo, but if not it's important to note that image_index starts at 0. So 5 images would be 0-4, rather than 1-5.

var xpos=0;
var ypos=0; 
xpos=obj_magnet.x; 
ypos=obj_magnet.y;
if(xpos>435&&xpos<704&&ypos>350&&ypos<640) { with(obj_lamp){
instance_change(obj_lamp_light,true);} if
obj_lamp_light.image_index==5{ obj_lamp_light.image_speed=0;} // should be object_lamp_light.image_index == 4
with(obj_arrow){
instance_change(obj_arrow_move_one_direction,true);}
if obj_arrow_move_one_direction.image_index==4{
obj_arrow_move_one_direction.image_speed=0;}
with(obj_arrow_move_opposite_direction){
instance_change(obj_arrow,true);}
exit;
}
else{
with(obj_lamp_light){
instance_change(obj_lamp,true);}
with(obj_arrow_move_one_direction){
instance_change(obj_arrow_move_opposite_direction,true);
if obj_arrow_move_opposite_direction.image_index==4{
obj_arrow_move_opposite_direction.image_speed=0;}}
exit;
}

Better yet, if you're checking to make sure that the object's image_indexes are equal to the last sub-image you could use image_number and subtract by one. This way if you ever add more sub-images you could ensure your code is still checking for the last frame.

A. Campbell
  • 404
  • 2
  • 12