Error! Help(Solved)

W

WolfYouTube

Guest
So I always get this error
Unable to find any instance for object index '0' name 'obj_Player'
at gml_Object_obj_enemy_StepNormalEvent_1 (line 4) - mp_potential_step_object(obj_Player.x,obj_Player.y,1,obj_enemy);

I don't know why but I do here's my code
if instance_exists(obj_test)
exit;
if(obj_enemy) mp_potential_step_object(obj_Player.x,obj_Player.y,1,obj_enemy)
sprite_index = spr_ZombieMove
image_speed = .5
if(obj_Player.x < x) {
image_xscale = .27;
} else {
if(obj_Player.x > x) {
image_xscale = -.27;
if(obj_Player.y > y) {
image_yscale = -.33;
}
}}
 
A

Aura

Guest
It is possible that the player instance does not exist at the time when this code is executed. You should make sure that the player instance exists before executing that code.

Code:
if (instance_exists(obj_player)) {
   //All the code that uses obj_player
}
Also, there's no point of if (obj_enemy) there.
 
F

Fodderbot

Guest
Code:
if (instance_exists(obj_test))
     {
     exit;
     }
//I am having a hard time deciphering this next if statement
// there are no opening or closing brackets for the lines that it enacts
// the perens in the statement themselves are confused
// all of the if things being checked should be contained in a single set of brackets
// so I would present this like :  added brackets may be incorrect.  you may want to position the lower one
// to under mp_potential... if that was your intent.

if (obj_enemy) {
     mp_potential_step_object(obj_Player.x,obj_Player.y,1,obj_enemy)
     sprite_index = spr_ZombieMove
     image_speed = .5
     }
if(obj_Player.x < x)
     {
     image_xscale = .27;
     } else
          {
          if(obj_Player.x > x)
               {
               image_xscale = -.27;
               if(obj_Player.y > y)
                    {
                    image_yscale = -.33;
                    }
               }
         }
MyQuestions???
Where do your create the instance you are wanting to move? Do you know its scope, or are you trying to reference all instances of the object in question?
 
Last edited by a moderator:

TheouAegis

Member
if(obj_enemy)
What the hell is this supposed to be? That conditional will always return true if obj_enemy isn't the very first object in the resource list, or it will always return false if obj_enemy is the first object in the resource list. All you're saying is, "if obj_enemy isn't the first object in the resource list, move toward the player."

Did you use instance_change or instance_destroy or instance_deactivate anywhere for the player?
 
W

WolfYouTube

Guest
It is possible that the player instance does not exist at the time when this code is executed. You should make sure that the player instance exists before executing that code.

Code:
if (instance_exists(obj_player)) {
   //All the code that uses obj_player
}
Also, there's no point of if (obj_enemy) there.
I thought that if I but that there if obj_enemy exists the code would exit
 
W

WolfYouTube

Guest
It is possible that the player instance does not exist at the time when this code is executed. You should make sure that the player instance exists before executing that code.

Code:
if (instance_exists(obj_player)) {
   //All the code that uses obj_player
}
Also, there's no point of if (obj_enemy) there.
Yeah because I want if object test exists exit the code
 
Top