need help with enemy pathing

J

jaigantor

Guest
hey, enemy pathing is crashing the game whenever the player dies here's the code:

if object_exists(o_player){
if point_distance(x,y,o_player.x,o_player.y) < 400{
Path_to_player();
}
}else if (!object_exists(o_player)){
if (path_exists(path)){
path_delete(path);
}
}
alarm[0] = room_speed;


it's giving me the error on line 3
Path_to_player(); is just the script for the enemy pathing
 

Flaick

Member
Could you post the stack trace please? And also the Path_to_player() code?

Maybe Path_to_player() does something with o_player while it's already destroyed?
 
J

jaigantor

Guest
Could you post the stack trace please? And also the Path_to_player() code?

Maybe Path_to_player() does something with o_player while it's already destroyed?
the issue isn't with Path_to_player()
the issue is coming from the line if point_distance(x,y,o_player.x,o_player.y) < 400
because the instance needs to exist for that to work, but the player is destroyed so it crashes because it is trying to check for something that is impossible ( a distance to an object that simply doesn't exist)
i just don;t know an alternative to what im using
 

Flaick

Member
Try replace object_exists() with instance_exists().

From object_exists() documentation: "...checks to see if an object is present in the resource tree, and not actually in the game room. For that you should use the function instance_exists."
 
Top