GML Object Help

A

Amoses

Guest
I am a pretty new user of GMS and I had one object following another and when the first object collides with the second object, the second object deactivates except I get the following error
Unable to find any instance for object index '23' name 'obj_boy'
at gml_Object_obj_jason_Step_0 (line 6) - direction = point_direction(x, y, obj_boy.x, obj_boy.y);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_jason_Step_0 (line 6)
if anybody knows how to fix this please let me know, i have searched everywhere and could not find a fix
 

DarthTenebris

Definitely not a Sith Lord
A deactivated object is as good as a non-existent object, so anything that relies on it won't be able to do anything with it and thus crash your game. Looking at the error you posted it seems like you deactivated obj_boy, and that causes issues with point_direction(), as it can no longer find the object.

Possible fixes:
1. Just disable its drawing. Set the variable visible to false, and it won't show up anymore, in case you tried to make it seem dead.
2. Check for existence before attempting to calculate. Surround point_direction() with instance_exists(object).
Code:
if (instance_exists(obj_boy)) {
     direction = point_direction(x, y, obj_boy.x, obj_boy.y);
}
This will make sure you only calculate the angle if you can, otherwise it will stay what it was last time it was able to check.

Aside from that I'd like to know what you're hoping to achieve by deactivating a colliding object, perhaps it could allow others to offer a better solution to your needs.

Hope I helped :)
 
Top