• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows Unable to find any instance for object index '102533' name '<undefined>

S

superhumqn

Guest
I'm currently trying to make an Artificial Intelligence for a flappy bird game. I have a 2D array of birdAI instances. After one generation, and the code below runs, it always gives this error:
Unable to find any instance for object index '102533' name '<undefined>'
at gml_Object_control_StepNormalEvent_1 (line 7) - if (global.generations[global.generation, i1].object_index != undefined) {

I'm running so many checks to see if the object is undefined, but none of them are helping.
global.populationSize is 25,
score1 is a variable inside the birdAI instance, same with fitness

Code:
if (!instance_exists(birdAI)) {
    sum = 0;
    //show_debug_message(global.generation);
    for (i1 = 0; i1 < global.populationSize - 10; i1+=1) {
        instance_activate_object(global.generations[global.generation, i1]);
        if  (global.generations[global.generation, i1] != undefined) {
            if  (global.generations[global.generation, i1].object_index != undefined) {
                show_debug_message(object_get_name(global.generations[global.generation, i1].object_index));
                if (global.generations[global.generation, i1].object_index.score1 != undefined) {
                    instance_activate_object(global.generations[global.generation, i1]);
                    show_debug_message(string(global.generations[global.generation, i1]));
                    sum += global.generations[global.generation, i1].score1;
                }
            }
        }
    }
    for (i2 = 0; i2 < global.populationSize - 10; i2+=1) {
        //show_debug_message(i2);
        global.generations[global.generation, i2].fitness = global.generations[global.generation, i2].score1/sum;
    }
    global.generation += 1;
    room_restart();
    for (i = 0; i < 24; i += 1) {
        global.generations[global.generation, i] = instance_create(128, 192, birdAI);
    }
}
Here's the console output:
Code:
birdAI
102508
birdAI
102509
birdAI
102510
birdAI
102511
birdAI
102512
birdAI
102513
birdAI
102514
birdAI
102515
birdAI
102516
birdAI
102517
birdAI
102518
birdAI
102519
birdAI
102520
birdAI
102521
birdAI
102522
ERROR!!! :: ############################################################################################
FATAL ERROR in
action number 1
of  Step Event0
for object control:


Unable to find any instance for object index '102533' name '<undefined>'
 at gml_Object_control_StepNormalEvent_1 (line 7) -             if  (global.generations[global.generation, i1].object_index != undefined) {
############################################################################################
and here's where its creating the array:
Code:
for (i1 = 0; i1 < 100; i1 += 1) {
    for (i = 0; i < global.populationSize; i += 1) {
        global.generations[i1, i] = instance_create(182, 192, birdAI);
        instance_deactivate_object(global.generations[i1, i]);
    }
}

for (i = 0; i < global.populationSize; i += 1) {
    global.generations[global.generation, i] = instance_create(182, 192, birdAI);
}[/
 
S

superhumqn

Guest
I dont have a clue how, but setting the birdAI instances to persistent helped.
 

samspade

Member
Code wise, the undefined check won't work because you're still checking for it. In other words this line:

Code:
global.generations[global.generation, i1].object_index != undefined
Is attempting to reference an instance in the first half. If that instance doesn't exist, it causes an error. Or to put it another way you're saying look at this instance's object_index and see if its object_index is undefined, but you can't look at an instance's object_index if the instance doesn't exist in the first place. The correct check is instance_exists().

As far as I know persistence only matters for room changes. Are you changing rooms somewhere? Using room_restart?

Edit: as an additional note, this is also a much better problem to solve using the debugger than show_debug_message. If the above isn't helpful in solving it, limit the generations to a more reasonable debugging number and step through it in the debugger, iteration by iteration. Even just letting it fail with the debugger can be useful because you'll be able to check what the arrays contain, what instances exist, and so on in the debugger rather than just getting the debug message.
 
Top