GameMaker [Solved] Find a certain sprite in Assets Layer

D

Dark Pyro

Guest
Hello people!

I have another issue...

I'm trying to find a certain sprite I placed on an asset layer, the problem here is, for some reason I can't find them.

I tested with certain functions like "layer_get_id("Assets")" in which returns 1, so it found the layer.
But when I actually look for the sprite with the "layer_sprite_exists(layer_get_id("Assets"), sSpriteToBeFound)" it doesn't return true.
I also tried to put sSpriteToBeFound.id and also "layer_get_id(layer_get_id("Assets"), sSpriteToBeFound))" and nothing comes up...

Any help on how I can find the sprite I'm looking for?

Much thanks!!!!
 

Relic

Member
Layer_sprite_exists requires an element id. This is not the same as the name on the resource tree- it is closer to an instance id but you can’t generalise it out like you would when referring to any/all instances of an object.

You will need to use layer_sprite_get_id() to obtain the element id before manipulating this sprite in an asset layer further.
 
D

Dark Pyro

Guest
Layer_sprite_exists requires an element id. This is not the same as the name on the resource tree- it is closer to an instance id but you can’t generalise it out like you would when referring to any/all instances of an object.

You will need to use layer_sprite_get_id() to obtain the element id before manipulating this sprite in an asset layer further.
Thanks for your answer!

That makes sense...
But I did use the layer_sprite_get_id(). Am I using it wrong? Based on the examples in the manual, the only thing that it's different it's the fact that it's between quotation marks. Although I tried in my code and it returned -1...
 

Relic

Member
layer_sprite_get_id(layer_get_id(“Assets”),sSpritetobefound)

Your original post had something similar, and maybe it was just a typo but you were trying to find the layer id, not the element id of the sprite asset.
 
D

Dark Pyro

Guest
layer_sprite_get_id(layer_get_id(“Assets”),sSpritetobefound)

Your original post had something similar, and maybe it was just a typo but you were trying to find the layer id, not the element id of the sprite asset.
Thanks for answering me!

I did that, unless there's something I'm missing or getting wrong and don't know...
This is the code I'm using

Code:
show_debug_message(layer_get_id("Assets"));
show_debug_message(layer_sprite_get_id(layer_get_id("Assets"), sFireRealm));
The sprite in question is sFireRealm.

Thanks once again! ^^
 

TheouAegis

Member
Just to be sure you are clear on this, the second argument is NOT a resource an asset like a sprite or object, it is an asset element, like an instance (but in this case, an instance of a sprite). That is why in the example in the help file they put it in quotes, because that is the name of the asset element, not the name of the Sprite.

edit: updated terminology
 
Last edited:
D

Dark Pyro

Guest
Just to be sure you are clear on this, the second argument is NOT a resource like a sprite or object, it is an asset, like an instance (but in this case, an instance of a sprite). That is why in the example in the help file they put it in quotes, because that is the name of the asset, not the name of the Sprite.
Ohh, I wasn't understanding that way...

How do I get the name of that asset instead the name of the instance?^

Thank you for the explanation and your help. I wasn't understanding it in that way!
 

TheouAegis

Member
If you put the Sprite on the lair using the room editor, double click on the Sprite to get its name. Otherwise, if you added it to the room via code, then the function returns the ID automatically.
 
D

Dark Pyro

Guest
If you put the Sprite on the lair using the room editor, double click on the Sprite to get its name. Otherwise, if you added it to the room via code, then the function returns the ID automatically.
It worked! It returned 2!!!

Thanks for all the help and explanations!!

Much love!! <3 <3
 
Just saw this after spending over an hour wondering why it wasn't working. This may be the dumbest and most non-newbie-friendly thing I have EVER seen in Game Maker. The manual does NOT help whatsoever in understanding that it is the sprite's name in the map and not just the sprite's name. Thank you for saving me literal hours I guarantee I never would've checked the map name.
 

TheouAegis

Member
Oh natural respect, I'm going to need to edit my response because I'm surprised it even helped you with the way everything is phrased in GMS2023. In the old days, "assets" were resources, so I called "elements" assets back then.
 
Top