instance_create_layer, issues any help would be great!

J

Jace

Guest
instance_create_layer(target_x, target_y,"PlayerLayer", obj_Player)

Hi everyone, I have been working on a game in GM for a little over a year. I am trying to port it over line by line to GM2 instead of using the conversion tool. I ran into an issue on the multiplayer side of things when I am trying to render a player to the world.

I added an instance layer called "PlayerLayer" to all of my rooms. I then call the above code to create the player in that layer when they connect to the server.

The game crashes upon connection to the server stating:

instance_create_layer :: specified layer "PlayerLayer" does not exist.

-Jace
 

Tthecreator

Your Creator!
1. this post fits better inside the game maker studio 2 section on this forum instead of the programming.
2. you can use layer_exists() to at least prevent your game from crashing...
3. What happens if you use layer_get_id(layer_name) and then pass the id to instance_create_layer instead of the string?
 
J

Jace

Guest
First, thanks for your reply and to respond in order:

1. Did not see a GM2 Programming section.
2. This did indeed keep the game from crashing just did not render the player sprite.
3. This returns layer -1, so for some reason GM2 is thinking the layer does not exist.
 
A

Ariak

Guest
Is your player a persistent object? In that case the layer will indeed show as nonexistent after first leaving the room it was created in.

instace_create_layer(x,y,"layerPlayer",obj_player) should work. However layer="layerPlayer" does not.
 
J

Jace

Guest
Is your player a persistent object? In that case the layer will indeed show as nonexistent after first leaving the room it was created in.

instace_create_layer(x,y,"layerPlayer",obj_player) should work. However layer="layerPlayer" does not.
It is, however, I changed the player from Persistent to not and it still returns -1. Might help if I just show all of the code:

goto_room = asset_get_index(target_room);
room_goto(goto_room);


layer1 = layer_get_id("PlayerLayer");
show_debug_message(layer1);
with(instance_create_layer(target_x, target_y,layer1, obj_Player)){
name = other.name
}

The above code is retrieving the room name from the server "target_room." It will then have GM render the room and finally the player. I have triple checked that the layer exist on the room.

Edit:

For some reason my browser is not liking the code block, hope you can make it out.
 
J

Jace

Guest
This issue has been solved: I created the PlayerLayer on the fly and everything is kosher.
 
Top