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

Question - Code instance_create_layer() issues

D

Daniel O'Brien

Guest
Hi all,
I've been having some issues with instance_create_layer() and wanted to see if anyone else was also experiencing issues. Straight off it appears that there is a small typo on the documentation located here whereby the 'obj' for the final argument is written down as 'y'. The bigger issue i'm having is that I have 4 properties stored in an array which i'm trying to pass to the function like so:
instance_create_layer(array[0], array[1], array[2], array[3]);
However, according to the error I get, for some reason gamemaker is trying to create an object using the X value located in array[0] and is therefore coming up with the error regarding how it couldn't create an instance with the ID of <xvalue>. Is anyone else experiencing this issue or is it just me?
Thanks in advance.
 

gnysek

Member
It's hard to tell without an example on how you're assigning things to your array.

But, check this one, as it's more error-aware:
Code:
var l = layer_get_id(array[2]); // name of layer
if (l > -1) {
    instance_create_layer(array[0], array[1], l, array[3]);
} else {
    show_debug_message("layer " + array[2] + " not exists");
}
 
D

Daniel O'Brien

Guest
It's hard to tell without an example on how you're assigning things to your array.

But, check this one, as it's more error-aware:
Code:
var l = layer_get_id(array[2]); // name of layer
if (l > -1) {
    instance_create_layer(array[0], array[1], l, array[3]);
} else {
    show_debug_message("layer " + array[2] + " not exists");
}

Here is the code:
Code:
    entity_array = ds_list_find_value(global.player_data, i);
    show_debug_message(entity_array[0])
    instance_create_layer(entity_array[1],entity_array[2],entity_array[3],entity_array[0]);
Here is the output (or the useful bit):
Code:
object_enemy_juanemy
ERROR!!! :: ############################################################################################
ERROR in
action number 1
of  Step Event0
for object object_player:


Creating instance for non-existing object: 1472
 at gml_Script_data_importer (line 20) -     instance_create_layer(entity_array[1],entity_array[2],entity_array[3],entity_array[0]);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_data_importer (line 20)
called from - gml_Object_object_player_Step_0 (line 78) -     data_importer(); //Run the data import script

Attempting to set gamepadcount to 0
---------------------------------------------------------------
From this you can see that the 'show_debug_message(entity_array[0])' returns object_enemy_juanemy. However, the error is 'Creating instance for non-existing object: 1472' (which is the X coordinate) despite the documentation saying correct usage of the function is 'instance_create_layer(x, y, layer_id, obj)' and entity_array[0] is the 4th piece of data passed to the function whereas the function seems to actually be taking '1472' from entity_data[1] instead which is the first parameter of instance_create_layer()
 

gnysek

Member
Here is the code:
Code:
show_debug_message(entity_array[0])
From this you can see that the 'show_debug_message(entity_array[0])' returns object_enemy_juanemy.
And here is your error. It should show ID of object, not it's name - so a integer value (0,1,2,...). You have string here, and that's why this function isn't workig.

Try show_debug_message(object_enemy_juanemy) and show_debug_message("object_enemy_juanemy") to see difference.
 
D

Daniel O'Brien

Guest
And here is your error. It should show ID of object, not it's name - so a integer value (0,1,2,...). You have string here, and that's why this function isn't workig.

Try show_debug_message(object_enemy_juanemy) and show_debug_message("object_enemy_juanemy") to see difference.
Thanks a lot! my code isn't throwing up errors now. That error message was extremely missleading though
 
Top