G
greggman
Guest
I'm trying to iterate through layers and then all the elements in each layer and print out the names. I figured out how to do this for sprites but not for instances
The short version is I call object_get_name but I'm guessing I need to do something else.
For sprites this code works though
What should I do instead?
Here's the entire loop
I have a feeling those instance ids are not what I need to get a name.
Would also like to be able to get names of tiles as well or rather the name of the tileset they came from and all the other objects as well but for now just being able to get instance names would be useful.
The short version is I call object_get_name but I'm guessing I need to do something else.
Code:
var __inst = layer_instance_get_instance(__id);
var __name = object_get_name(__inst); // <==== this just returns <undefined>
Code:
var __spr = layer_sprite_get_sprite(__id);
var __name = sprite_get_name(__spr);
What should I do instead?
Here's the entire loop
Code:
var __layers = layer_get_all();
var __numlayers = array_length_1d(__layers);
var __i;
for(__i = 0; __i < __numlayers; __i++)
{
var __layer_id = __layers[__i];
var __els = layer_get_all_elements(__layer_id);
var __numels = array_length_1d(__els);
show_debug_message("layer: " + string(__i) + " " + layer_get_name(__layer_id) + "[" + string(__numels) + "]");
var __j;
for(__j = 0; __j < __numels; __j++)
{
var __id = __els[__j];
var __eltype = layer_get_element_type(__id);
if (__eltype == layerelementtype_instance)
{
var __inst = layer_instance_get_instance(__id);
var __name = object_get_name(__inst); // <==== this just returns <undefined>
show_debug_message(" instance:" + string(__j) + ": " + __name);
}
else if (__eltype == layerelementtype_sprite)
{
var __spr = layer_sprite_get_sprite(__id);
var __name = sprite_get_name(__spr);
show_debug_message(" sprite: " + string(__j) + ": " + __name);
}
else if (__eltype == layerelementtype_background)
{
show_debug_message(" background: " + string(__j));
}
else if (__eltype == layerelementtype_tilemap)
{
show_debug_message(" tilemap: " + string(__j));
}
else if (__eltype == layerelementtype_particlesystem)
{
show_debug_message(" particlesystem: " + string(__j));
}
else if (__eltype == layerelementtype_tile)
{
show_debug_message(" tile: " + string(__j));
}
else
{
show_debug_message(" unknown: " + string(__j));
}
}
}
Would also like to be able to get names of tiles as well or rather the name of the tileset they came from and all the other objects as well but for now just being able to get instance names would be useful.