Closed Retrific closed 1 year ago
You can check for whether a given value matches a sprite by using sprite_exists(some_sprite)
, though it will also match the underlying numeric ID.
To make sure that you are dealing with a proper sprite reference (rather than a number that happens to have value as one of sprite identifiers), you can additionally use is_handle(some_sprite)
. Thus, here's an example custom implementation of is_sprite
:
function is_sprite(_value) {
return is_handle(_value) && sprite_exists(_value);
}
And here are some debug messages to see how it works:
show_debug_message($"sprite_exists(Sprite1) = {sprite_exists(Sprite1)}"); // true, OK
show_debug_message($"sprite_exists(real(Sprite1)) = {sprite_exists(real(Sprite1))}"); // true, but it's a number!
show_debug_message($"is_sprite(Sprite1) = {is_sprite(Sprite1)}"); // true, OK
show_debug_message($"is_sprite(real(Sprite1)) = {is_sprite(real(Sprite1))}"); // false, OK
To add from above, I made a whole gist for all of these a lil while ago. https://gist.github.com/tabularelf/615e22bc70aeb382e42b15a365e80ed9
It'd definitely be nice to have a better way to identify what kind of ref something is. When using the new tilemap collision with an array that also has objects, there's not really a direct way to check if what was collided with is a tilemap. Instead you have to check if it's NOT an instance.
Ah I was not aware of is_handle, thats at least something
use asset_get_type() which will tell you what asset type the reference is...
asset_get_type()
only takes in a a string, not a reference...
We should allow it to take refs too... I will take a look at that
Fixed in 2023.11 - asset_get_type will now take a reference - this will require a mention in the documentation @gurpreetsinghmatharoo @YYBartT
Reopening as asset_get_type() is not accepting tileset references, and feather warnings are being returned if we use references instead of strings.
I have updated the asset compiler to fix the tileset issue and the GmlSpec.xml for asset_get_type
has been updated to allow for either a string or an asset. Several other functions also use that signature for arguments..
Unfortunately Feather does not interpret the Asset
type properly as meaning any asset.
I talked to @zreedy and he is going to add that to Feather, so until that is in you will still get errors like
Here is an updated project, this fixes the original projects timeline problem [GM-1325.zip…]()
Feather now interprets Asset parameter types without a Specifier as matching any Asset, with or without a Specifier.
The changes for feather are ready and merged @rwkay
Marked this one as Done now, as it's obvs been in for a while already.
Verified fixed in IDE v2023.1100.0.448 Runtime v2023.1100.0.457
Is your feature request related to a problem?
Now that every reference to an asset (like sprites) seems to know its a reference to a specific asset type, as you can see when turning them into strings (string(somesprite) becomes "ref sprite 49"), it only makes sense to also get that information directly, without having to analyze the string version of a variable.
Describe the solution you'd like
Add functions like is_sprite, is_object, is_instance etc. just like is_struct or is_callable.
Alternatively update typeof(), which by the way also returns "ref" for sprite references, not just instance references.
Describe alternatives you've considered
Analyzing the stringified version of the ref
Additional context
No response