0

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

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

"Especially the with(), as that function will go through every object in the room if it sees an object within the parameter" - not at all, with can be used to execute code in scope of a single object (or struct), and the author's use case is demonstrated in the manual.
I see, I've only used it with just the object as parameter, so I wasn't aware it could be used for much more purposes. So that's interesting!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.