Senkyetsu
Senkyetsu

Reputation: 1

GMS2 returns instance_create_layer :: specified layer "text_layer" does not exist even though the layer exists how do i fix this?

heres the code



var _obj;

if (instance_exists(obj_text)) _obj = obj_txt_queued; else _obj = obj_text;
with (instance_create_layer(0, 0, "text_layer", _obj))
{
    msg = argument[0];
    if (instance_exists(other)) originInstance = other.id else originInstance = noone;
    if (argument_count > 1) background = argument[1]; else background = 1;
    
}

with (obj_phae)
{ if (state != scr_player_state_lock)
    { 
        lastState = state;
        state = scr_player_state_lock;
    }
}

[layers](https://i.sstatic.net/9u9tD.png)

I tried removing any extra rooms that were not needed and I tried changing the layer name to something else.

I also tried using var instance_create_layer() but that obviously didn't work

Upvotes: 0

Views: 390

Answers (1)

Steven
Steven

Reputation: 2122

I'm a bit confused at this part:

with (instance_create_layer(0, 0, "text_layer", _obj))

Especially the with(), as that function will go through every object in the room if it sees an object within the parameter, since you suggested to create a new object with it, I'm surprised it doesn't create an infinite loop. Maybe it works, I've never tried it myself, but I think there's a more logical way to assign variables from one object to a newly created object.

Assuming you want to use the With() statement to address the variables within the _obj, I think you can manage something similair through this function:

var object = instance_create_layer(0, 0, "text_layer", _obj)
object.msg = argument[0];
object.originInstance = id
if (argument_count > 1) object.background = argument[1]; else object.background = 1;

It's probably a given at this point, but double-check that this part of code can only run if it's in the same room that has a layer called "text_layer"

In the worst case, you may also try out instance_create_depth() and use the build-in depth variable from the object instead of the layer names. Using depth is more flexible, but less organised than layers.

Upvotes: 0

Related Questions