• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Mac OSX Unable to find any instance for object index ERROR

U

Ufy

Guest
So here's the error:

Code:
Unable to find any instnace for object index ‘100080’

at gml_Object_oWaddleFriend_Step_0 (line 111)

bullet.creator = id;
Here's the code that seems to cause the error:
Code:
if(target.x > x) {
            bullet = instance_create_layer(x+4, y+10, "bullet", oBulletFriend);
                bullet.creator = id;
            } else {
            bullet = instance_create_layer(x-4, y+10, "bullet", oBulletFriend);
                bullet.creator = id;
            }

Here's what the oBulletFriend object code looks like:
Code:
creator = noone
if(creator!=noone) {
direction = point_direction(x,y, creator.target.x, creator.target.y);
speed = 10;
} else {

instance_destroy()

}
How do I fix this error?
 

2Dcube

Member
When you create the oBulletFriend instance, it first executes its creation code.
Only after that does it go to the next line "bullet.creator = id".
In the creation code you destroy the instance. It never executes
Code:
direction = point_direction(x,y, creator.target.x, creator.target.y);
speed = 10;
because at that point creator is always noone. Because you've just set it to be so.

When it tries to tell "bullet" that it's creator equals "id", "bullet" has been destroyed and does not exist.

Solution:
You could run the code that's now in the creation event in an alarm, and set the alarm to 1 step in the creation code. This way, the object is created, get's its "creator" variable set, and then a frame later it is checked.
Create Event:
Code:
creator = noone;
alarm[0] = 1;
Alarm[0] Event:
Code:
if(creator!=noone) {
direction = point_direction(x,y, creator.target.x, creator.target.y);
speed = 10;
} else {

instance_destroy()

}
Other solutions:
You could check the creator variable in oWaddleFriend after you've created the bullet instance.
 
  • Like
Reactions: Ufy
U

Ufy

Guest
When you create the oBulletFriend instance, it first executes its creation code.
Only after that does it go to the next line "bullet.creator = id".
In the creation code you destroy the instance. It never executes
Code:
direction = point_direction(x,y, creator.target.x, creator.target.y);
speed = 10;
because at that point creator is always noone. Because you've just set it to be so.

When it tries to tell "bullet" that it's creator equals "id", "bullet" has been destroyed and does not exist.

Solution:
You could run the code that's now in the creation event in an alarm, and set the alarm to 1 step in the creation code. This way, the object is created, get's its "creator" variable set, and then a frame later it is checked.
Create Event:
Code:
creator = noone;
alarm[0] = 1;
Alarm[0] Event:
Code:
if(creator!=noone) {
direction = point_direction(x,y, creator.target.x, creator.target.y);
speed = 10;
} else {

instance_destroy()

}
Other solutions:
You could check the creator variable in oWaddleFriend after you've created the bullet instance.
Thank you so much! You're a live saver! I've been busy thinking about this for hours now.
 

gnysek

Member
What I learned over years, is that it's secure to use with(), as

Code:
with (xxx) { var = 4; speed += 0; other.direction = 100; }
is same as:

Code:
if (instance_exists(xxx)) { xxx.var = 4; xxx.sped += 0; direction = 100}
You need to remember, that inside "with" code is not called anymore from current scope, but from called instance scope (as above - need to use "other" to access current instance).
 
Top