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
Here's the console output:
and here's where its creating the array:
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);
}
}
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) {
############################################################################################
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);
}[/