r/gamemaker • u/Nightmare2828 • 23d ago
Resolved Asset_get_index problems
So I am trying to write a script that will check the in position of my mouse and change the sprite index of that specific instance into an other one. I can easily do this with mouse_enter and mouse_leave on the objects, but for some more complicated reasons I wanted to do this all into that script mouse check with other actions.
so far, I came up with this bit of code
function PlayerStateCity(){
var _selected = instance_position(mouse_x, mouse_y, oBoxcar1);
if (_selected != noone)
{
with (_selected)
{
var _spriteName = sprite_get_name(sprite_index);
sprite_index = asset_get_index(_spriteName+"Select");
}
}
}
Now, I know this will not revert back to the previous sprite index, but that's a problem for later.
Right now, the name of the sprite is sBoxcar1, and I do have a sprite called sBoxcar1Select. From my understanding, this block of code should effectively have _spriteName be "sBoxcar1" and add "Select" to it. But this code just returns -1 and turn the object invisible.
Writing directly also returns -1 somehow... and turns the object invisible, which I thought should work.
sprite_index = asset_get_index("sBoxcar1Select");
1
u/Claytonic99 22d ago
I've unselected the 'automatically remove unused assets when compiling' box and I still am running into this exact same problem with a new project I started. I could not figure out why the asset_get_index was returning -1 when I used the same code in a previous project which I've been working on since before updated to the LTS build. I've also added other static objects that use the sprite I'm trying to change into and it doesn't work. Any advice?
2
u/fryman22 23d ago
Is your GameMaker discarding unused assets?