GameMaker [SOLVED] Gamemaker not evaluating layer_tilemap_get_id

SOLVED: For anyone reading this who is having the same issue of the Debug menu not evaluating tile functions, the solution is simple: the Debug menu shows false results for these functions. You can still use them in code as normal, and they will work perfectly fine.

I just recently moved from GM8.1 to GM:S2 (due to not having a license for 8.1...), and I'm working on getting my current project copied over. In my original project, I had a nigh-perfect tile-based collision system which depended on the old tile_layer_find function. Upon doing my homework, I've found out about the new function that I need to serve that same purpose, tilemap_get_at_pixel, and that it requires the ID of the tilemap in the layer to function, which can be gotten by using layer_tilemap_get_id. However, when I try to make the new collision system, the game cannot perform the collisions, and, after tracking a few things in the Debug's Watch section, I've found out why: for some reason, the game is not evaluating layer_tilemap_get_id. I would like to know why.

The function I'm testing in the debugger is as follows:
layer_tilemap_get_id ("layer_walls")
layer_walls being the name I've given to the layer holding my wall tiles.

I've checked the spelling on the layer name several times, to no avail; I've tried using layer_get_id instead, and it encounters the same issue; I've tried removing the string quotations, which just crashed the game (expectably); I've even tried renaming the layer- all to no avail. If anyone has an idea what I'm doing wrong, I'd love to hear it so that I can carry on past this roadblock. I simply want to understand what I'm doing wrong with this function so that I may use it correctly.

Thank you kindly!
~Pir
 
Last edited:

Gzebra

Member
I haven't worked with the tilemaps at all really, but I'm fairly sure you're not suppose to use a string as the argument for layer_tilemap_get_id.
 
I haven't worked with the tilemaps at all really, but I'm fairly sure you're not suppose to use a string as the argument for layer_tilemap_get_id.
... Hm? The documentation says that I can slap the layer name in there as a string. I can't link it because I don't have enough posts to do so, but I can quote the relevant prose...

"This function can be used to retrieve the unique ID value of the tilemap element on a layer. You supply the layer ID (which you get when you create the layer using layer_create()) or the layer name (as a string - this will have a performance impact) and the function will return the ID value associated with the tilemap element on the layer. Note that this function is specifically designed for use with tilemaps that have been added in the IDE, as if you add a tilemap to a layer through code using the function layer_tilemap_create, then it will return the unique ID for the tilemap element added."

(While we're at it, I know about the performance impact, but I'm not masochistic enough to add layers- and, effectively, all of their tiles, one by one, position by position without being able to view them as I make them- through code.)
 
He's right for tilemaps, you would have to store the tilemap into the id

// Maybe this could help...
layer_tilemap_get_id( layer_get_id( "layer_walls" ) );
So I tried that code, as directed. Unfortunately, the game still can't evaluate it. Here's the Watch feedback: the global.wallsID is the variable in the code I'm using to store the walls layer's tilemap ID for use in the collision functions (having the game solve that out every step for collisions would drop performance like a stone, so I'm having it store that value instead), which uses your code to get that value, while the lower one is your code placed directly into the Watch box. It's puzzling for certain- according to the documentation, that should've worked...
 

Attachments

I think I know what the issue is. . .

We need to set this "layer_tilemap_get_id( layer_get_id( "layer_walls" ) );"
to a variable, I'm not sure exactly how you've your collisions setup, but
we need to use the variable to get use out of it.

//
var temp = layer_tilemap_get_id( layer_get_id( "layer_walls" ) );



So I tried that code, as directed. Unfortunately, the game still can't evaluate it. Here's the Watch feedback: the global.wallsID is the variable in the code I'm using to store the walls layer's tilemap ID for use in the collision functions (having the game solve that out every step for collisions would drop performance like a stone, so I'm having it store that value instead), which uses your code to get that value, while the lower one is your code placed directly into the Watch box. It's puzzling for certain- according to the documentation, that should've worked...
 
I think I know what the issue is. . .

We need to set this "layer_tilemap_get_id( layer_get_id( "layer_walls" ) );"
to a variable, I'm not sure exactly how you've your collisions setup, but
we need to use the variable to get use out of it.

//
var temp = layer_tilemap_get_id( layer_get_id( "layer_walls" ) );
I've already got that whole deal set up in my game, storing it under the variable global.wallsID, which I would then reference in the collision systems. When I watch that variable's value, the ID comes out as 0, which I assumed meant that it wasn't evaluating properly. Unless the ID of the tilemap element in the layer actually IS 0, and that's just how the game does things?

Then what I fail to understand is why the Watch tab in the Debug mode cannot evaluate the exact same function. Unless the Debugger simply cannot Watch layer ID functions...?
 
P

ph101

Guest
Are you using any tile compatability scripts or have you created a new tilesets in GM2 ?
 
P

ph101

Guest
Oh no I certainly dont suggest that! (Just that there may be some inconsistencies on the way they handle layers I have noticed so wanted to rule that out)

For your predicament I suggest you go further in your debugging. Where is the layer "layer_walls" given that name? Can you show that code or is it done in the IDE? Does it actually exists when you check using (layer_exists) ?
 
Oh no I certainly dont suggest that! (Just that there may be some inconsistencies on the way they handle layers I have noticed so wanted to rule that out)

For your predicament I suggest you go further in your debugging. Where is the layer "layer_walls" given that name? Can you show that code or is it done in the IDE? Does it actually exists when you check using (layer_exists) ?
I created the layer through the IDE's room editor, not through code, so it's given its name in there. When I tried to Watch layer_exists ("layer_walls"), it threw a "Failed to evaluate expression"- the thing simply refuses to evaluate it for some reason, just like how it refuses to evaluate the ID functions. I know that isn't of much help... but if it was simple, I would've solved it myself, am I right?
 
P

ph101

Guest
"if it was simple, I would've solved it myself, am I right?" - are you saying you don't want any more suggestions? :p

Sadly I personally never use the IDE to make layers so I can't help beyond breaking it down for some ideas. For sure though, these functions seem to be working for everyone else so it suggests it is something you have done..? (whether its simple or not, we cant say just yet!)

You will have thought of all this but hey just in case:

-As you said perhaps the watcher is giving false results? What specifically happens in code when you test if layer_exists and what value does it return when you use show_debug_message
-It suggests something is wrong with the way you have created and named the layer. It doesnt look like it but do you have any weird characters in it like " or anything? Does the same thing happen when you rename it something else?
-What happens when you start a new project and create a layer and see if it exists using layer_exists and show_debug_message - presumeably GM2 doesn't fail to detect all layers made in IDE...? (i mean it *could* but if you make an isolated project like this then you can at least submit the bug, if it does work in your project you can think more about what you have done differnetly..?) - or the process might reveal some other error you made creating the layer?
-have you altered or deleted the layer in code somehow latterly?
-Post a screen of the layer editor with the layer in question and all the exact code that interacts with the layer using [ code ] [ / code ] formatting and someone might be able to help you more.
-also, make sure your layers are in the correct room you are operating in
 
Last edited by a moderator:
Top