• 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!

Legacy GM Code trying to create an instance but cant find object

  • Thread starter David Kvistorf Larsen
  • Start date
D

David Kvistorf Larsen

Guest
So I got this following error message:

Code:
___________________________________________
############################################################################################
ERROR in
action number 1
of Create Event
for object objBattleController:

Creating instance for non-existing object: 100082
at gml_Object_objCallForHelp_ObjAlarm0_1 (line 60) - e[1] = instance_create(25+v_offset,120,global.enemy[1]).id;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_objBattleController_CreateEvent_1 (line 60)
called from - gml_Object_objCallForHelp_ObjAlarm0_1 (line 20) - global.enemy[ds_list_find_value(list, 0)] = (instance_create(irandom_range(32,288),irandom_range(64,144),choose(help_enemy1,help_enemy2,help_enemy3))).id
Now i understand what the error message is telling me, but I don't know how to fix it.

Here is the section of the code from objCallForHelp that is creating this error

Code:
if random(256) < 205 and instance_number(objEnPar) < 5 {
if global.en_count < 5 {
global.en_count++;
}
var list;
list = ds_list_create();

if global.enemy[1] = 0 { ds_list_add(list,1); }
if global.enemy[2] = 0 { ds_list_add(list,2); }
if global.enemy[3] = 0 { ds_list_add(list,3); }
if global.enemy[4] = 0 { ds_list_add(list,4); }
if global.enemy[5] = 0 { ds_list_add(list,5); }

global.enemy[ds_list_find_value(list, 0)] = (instance_create(irandom_range(32,288),irandom_range(64,144),choose(help_enemy1,help_enemy2,help_enemy3)))
global.totalexp += global.enemy[ds_list_find_value(list, 0)].e_exp
a.str[0] = upper(global.enemy[ds_list_find_value(list, 0)].e_art)+global.enemy[ds_list_find_value(list, 0)].e_name+" joined the battle!";
ds_list_destroy(list);
And here is the code for the objBattleController, which is called by objCallForHelp.

Code:
for (var i=1;i<6;i++) {
e = 0
}

switch global.en_count {
case 1:
e[1] = instance_create(160+v_offset,120,global.enemy[1]);
dropenemy = e[1];
break;
case 2:
e[1] = instance_create(102+v_offset,120,global.enemy[1]);
e[2] = instance_create(218+v_offset,120,global.enemy[2]); 
dropenemy = choose(e[1],e[2]);
break;
case 3:
e[1] = instance_create(160+v_offset,120,global.enemy[1]); 
e[2] = instance_create(80+v_offset,96,global.enemy[2]);
e[3] = instance_create(240+v_offset,96,global.enemy[3]);
dropenemy = choose(e[1],e[2],e[3]);
break;
case 4:
e[1] = instance_create(25+v_offset,120,global.enemy[1]);
e[2] = instance_create(115+v_offset,120,global.enemy[2]);
e[3] = instance_create(205+v_offset,120,global.enemy[3]);
e[4] = instance_create(295+v_offset,120,global.enemy[4]);
dropenemy = choose(e[1],e[2],e[3],e[4]);
break;
case 5:
e[1] = instance_create(160+v_offset,130,global.enemy[1]);
e[2] = instance_create(100+v_offset,86,global.enemy[2]);
e[3] = instance_create(220+v_offset,86,global.enemy[3]);
e[4] = instance_create(40+v_offset,130,global.enemy[4]);
e[5] = instance_create(280+v_offset,130,global.enemy[5]);
dropenemy = choose(e[1],e[2],e[3],e[4],e[5]);
break;
}

for (var i=1;i<6;i++) {
global.enemy = e
}
Does anybody see what I did wrong?
 

TheouAegis

Member
global.enemy[ds_list_find_value(list, 0)] = (instance_create(irandom_range(32,288),irandom_range(64,144),choose(help_enemy1,help_enemy2,help_enemy3)))

That sets global.enemy[ ] to an instance id.

e[1] = instance_create(160+v_offset,120,global.enemy[1]);

The instance_create() function requires an object_index, not an instance id.

Your code looks odd. I don't think it's anywhere near doing what you were hoping it would do. What's the point of your ds_list? You don't actually do anything with it; it's just there taking up space for a nanosecond.

for (var i=1;i<6;i++) {
e = 0
}

What the heck is the point of that line?

And what's so hard about starting from 0 instead of 1? You are wasting RAM by not counting from 0.
 
Last edited:
D

David Kvistorf Larsen

Guest
global.enemy[ds_list_find_value(list, 0)] = (instance_create(irandom_range(32,288),irandom_range(64,144),choose(help_enemy1,help_enemy2,help_enemy3)))

That sets global.enemy[ ] to an instance id.

e[1] = instance_create(160+v_offset,120,global.enemy[1]);

The instance_create() function requires an object_index, not an instance id.

Your code looks odd. I don't think it's anywhere near doing what you were hoping it would do. What's the point of your ds_list? You don't actually do anything with it; it's just there taking up space for a nanosecond.

for (var i=1;i<6;i++) {
e = 0
}

What the heck is the point of that line?

And what's so hard about starting from 0 instead of 1? You are wasting RAM by not counting from 0.
Well i am actually a prebuilt engine sort of, which is trying to emulate Earthbound. And I am trying to expirement with it, but somethings don't work too well, and that is what I am trying to fix. But thank you for the help.

By the way, the dsl list is supposed to check if any enemies has already taken the global enemy positions. Then it checks if there is any vacant slots, an the it tries to create the object on that spot. What do you think, should i change anything here?
 
Top