Mac OSX Solved

Nathan

Member

Per the manual it says" You need to supply the layer ID, which can either be the name of the layer as written in the code editor (as a string) or the actual layer ID value as returned by the layer_create,". Is this also the string name of a layer that is displayed in the room editor in the layer view? I just want to make sure I approach this correctly. Thanks!
 

TheouAegis

Member
Yes, the string is the name of the layer in the room editor. You should use the layer's id directly, though.
 

Nathan

Member
Thanks! So I tried using their examples but still nothing happens. Here's the setup. I have a room which has 2 layers in it : Controllers and Enemies (named in the Room Editor) both are Instance Layers. I have a room_controller object on the Controllers layer, and in it's creation code I am putting this :

var layer_id = layer_get_id("Enemies");
instance_deactivate_layer(layer_id);

The enemy layer does not deactivate. Where am I going wrong? How do I apply it inside the current room? Should this go in the room creation code?
 

TheouAegis

Member
If the Controller object is created inside the room in question, then it doesn't matter what event gets the layer's id. The layers are created before objects.

Are you sure you're not just mistyping the name of the layer? The function works just fine for me using layer name and using layer id (tested in YoYo Platform Lite). You can deactivate a layer during a Create event. Instances will still get created, but they won't draw.
 
Last edited:

Nathan

Member
Did you copy/paste the code I posted? I double checked spelling, it's all matched but still nothing happens. I created a new project with no other code but this, the 2 objects, and a room with 2 layers, still does not work. I've also tried making the Enemies layer invisible with the following code :

layer_set_visible(layer_id, false);

Nothing happens. Seems I can't change anything in the room and I'm not sure why.
 
Last edited:

TheouAegis

Member
Copying your code would do me no good because I'm not in your project.

ghosts = layer_get_id("Ghosts");
instance_deactivate_layer(ghosts);

That was the code I ran inside one of the official demos. I ran it in the Create event and in the Spacebar Press event. All of them worked just fine.

What version of Studio 2 are you running? I don't think mine is up to date, so that's something to consider.
 

Nathan

Member
Haha good catch. It now works in the test file, but not in my game. I wonder if my brother has some other script running that's conflicting? It should work this simple.
 

TheouAegis

Member
Haha good catch. It now works in the test file, but not in my game. I wonder if my brother has some other script running that's conflicting? It should work this simple.
Verify you actually typed the right name in (if layer_get_id() returns negative, that's a surefire sign). Verify the ID returned by layer_get_id() is actually an instance layer's and that there are instances on it. This is pretty easy -- open the room editor, look over on the layers' tab, then start counting from the top (starting with 0). Then as you said, make sure there isn't an instance_activate_* call somewhere disabling all your hard work.
 

Nathan

Member
Figured it out (as with the other post). Here is the further issue I face now (my brother does 98% of the programming but I'm starting to dig in with quarantine time)

In one of the controllers he is running a room_activator(); script on the begin step of the gameoverlord controller (object hat controls lots of things). It's a scrolling game so it is designed to activate anything that comes into the view. The problem now is when I deactivate the enemy layer, the script just reactivates them almost immediately. How could we get around the issue? I need to deactivate certain layers and only activate them when the player does certain things like collecting an object.
 

Attachments

TheouAegis

Member
Delete all those instance_activate_* calls, for starters. Everything you want deactivated at the start of the room will be on certain layers, which you deactivated. Everything you need active, like Tracker, will be on another layer you didn't deactivate. Any enemies getting reactivated immediately must be inside the view. If it's getting reactivated outside the view, that means all those view_top() and view_left() and whatnot scripts are at fault.

If your brother wrote this up in GM6 and ported it to GMS2, there are going to be a lot of changes required for it to run properly. A lot of things in GM6 aren't compatible with GMS2, even after the importer's conversion scripts are added.
 

Nathan

Member
I tried commenting all those out and it breaks the game entirely in so many different ways because of the way it's programmed. Is there a way to have the instance_activate_region ignore certain layers? It's activating everything that comes into the view (which is obviously what it's intended to do).

What it does is on room creation it deactivates all objects in the room to prevent enemies from being active and wandering around the stage, shooting you from the end where they are etc. It then reactivates things as they come on screen. My problem it I want to make a breakable wall with enemies behind it that you only see when you break the wall and enter it (same view). With the activate region all the enemies in the hidden room get activated when they are in the view, even though the room's layer will be hidden until you enter it. So the enemies appear in the black and attack when then shouldn't be active yet.
 
Last edited:

Nidoking

Member
If you want to evaluate complex conditions, you're going to have to write complex code. It's even more complex when dealing with deactivated instances, because you can't refer to them in any general way. Perhaps you should consider using the "visible" property instead. It causes things not to be drawn, even though they're still active and doing whatever else it is that they do.
 
Top