Layer_get_id (and similar functions) bug

Kealor

Member
I am having a very unique issue that appears to be specific to my project, but appears to be a bug in GMS2 as far as i can tell.

I have two layers of concern: "Tiles_arena_platforms" and "Tiles_foreground_top". My aim is to based on a bool, make the former visible/invisible. sounds simple enough and i have this code:

Code:
switch arenaStats[7]
{
   case false:
       instance_deactivate_object(objPlatformParent);
       layer_set_visible("Tiles_arena_platforms",0);
       break;
   case true:
       instance_activate_object(objPlatformParent);
       layer_set_visible("Tiles_arena_platforms",1);
       break;
}
Now the instance activates/deactivates work perfectly as needed, so i should expect the layer visibility to as well, but it doesnt. Instead of "layer_set_visible("Tiles_arena_platforms",0);" applying to the correct layer, it applies to "Tiles_foreground_top" instead!

I have tested this with many different names, layers, rooms, objects and i get the same occurence every time. I do not get the same error in a new project.

This suggest that it is something in my project causing this. However i dont believe it to be a fault in my code, or atleast a rational, acceptable one. I have read out the data returned by "layer_get_all" and every layer that is supposed to exist at this time does, and in the correct order (appended at the end). The layer room target is reset at this point and it is verified that this is uniform with layer_get_visible as it appears to be returning bugged results in other areas also.

If anything can be thought of to fix this issue it would be greatly appreciated, i cannot imagine why the system for determining layer ID based on name would return completely unreliable results.

Cheers for any help!

PS: One thing ive been wanting for a while is a function/variable to determine the current draw layer and/or depth (not the layer/depth of the current object, i mean the depth/layer in engine being processed). I believe this should be possible 99% of the time and would be extreeeemely useful when it comes to layer_set_script_begin/layer_set_script_end in setting the variables for shaders. There is a way to get this data by setting up a system of layer indeces and number of times a script has run, but that is overly complex and takes up valuable processing time just to determine a value that allready exists in memory.

Layers in the room:
196.png
layer_get_all data and the code used to read it out:
559
lay_technicals
560
lay_blocks
690
Controllers
561
Tiles_foreground_top
562
Tiles_foreground_c
563
Tiles_Col_Occ_foreground_b
564
Tiles_foreground_a
565
lay_lights
566
lay_player
567
lay_entities
568
lay_interactables
569
lay_effects_1
570
Tiles_arena_platforms
571
Tiles_arena_hookPoints
572
Tiles_background_d
573
Tiles_background_c
689
lay_effects1
574
Tiles_background_b
575
Tiles_background_a
Code:
var allLayers = layer_get_all();
for(var i = 0; i < array_length_1d(allLayers); i++)
{
    show_debug_message(allLayers[i]);
    show_debug_message(layer_get_name(allLayers[i]));
}
 
Have you tried:

Code:
layer_set_visible(layer_get_id("Tiles_arena_platforms"), false);
And have you tried using the actual true and false constants instead of 0 and 1?

Do either of those make a difference?
 

Kealor

Member
Have you tried:

Code:
layer_set_visible(layer_get_id("Tiles_arena_platforms"), false);
And have you tried using the actual true and false constants instead of 0 and 1?

Do either of those make a difference?
Nope it doesnt. But thats kind of to be expected, using 0/1 in place of bools is commonplace in gms. Anything that accepts a bool automatically converts ints to true if > 0 and false if <= 0.
 
What version of GMS 2 are you using?

There was a bug in an earlier version (actually I haven't tested if it has been fixed yet either) where if a room was persistent, after switching rooms, layer_set_visible() function no longer worked properly, the layer would stop responding to the function.

Also, any number less than or equal to 0.5 is actually considered false, > 0.5 is true.

EDIT : Just to clarify, I realize you can use real numbers for testing true or false based on its value, but the recommendation is to use true or false constants where appropriate. If I was getting bugs like this, I would suggest trying using the constants to rule out that as the cause.
 
Last edited:

Kealor

Member
my b, but yeah in the end that didnt fix it.

I have temporarily fixed it by setting up a ludicrously complex set of counters and layer trackers inside begining and end scripts to apply alphas manually.

It hurts performance but its not too drastic. (god i wish there was some "layer_get_current()" function or something.
 

rmanthorp

GameMaker Staff
Admin
GameMaker Dev.
Hey. While rendering, the instance variable “layer” is the id of the current layer that is rendering. When the layer scripts are being run the dummy instance that is used has the same variable set on it as well so you can easily access the current layer id :)
 
Top