S
Salvakiya
Guest
so I actually dont export to HTML5... And I hope I put this in the right forum... however I heard that HTML5 does not support asset_get_index. After finding this out I thought I would show a little trick which will allow you to do the same thing which should be supported by HTML5. I hope this helps!
you would then do something like this...
you can use this method for any asset type other than shaders. you could even combine them all into one map and you can use the same method to check for types and create a replacement for asset_get_type.
I would LOVE to know if its faster or slower than asset_get_index as well. I only recently came back to using GM and I remember maps being pretty slow in the past. If you know please let me know!
EDIT: you can also take a look at GML scripts for another way to do it... HOWEVER their map_objects contains an obsolete function and I have no idea if it would still work. My method is designed to be ran at game start and referenced throughout. these you could probably use to map during the game at any time as they will keep looking at all assets even if some have been deleted.
http://www.gmlscripts.com/script/Resources/Management/
EDIT: alternate script to GMLscripts map_objects
Code:
///index_sprites()
var map;
map = ds_map_create();
//Objects
var i = 0;
while sprite_exists(i){
map[? sprite_get_name(i)]= i;
i++;
};
return map;
Code:
sprites = index_sprites()
sprite_index = sprites[?"spr_player"]
I would LOVE to know if its faster or slower than asset_get_index as well. I only recently came back to using GM and I remember maps being pretty slow in the past. If you know please let me know!
EDIT: you can also take a look at GML scripts for another way to do it... HOWEVER their map_objects contains an obsolete function and I have no idea if it would still work. My method is designed to be ran at game start and referenced throughout. these you could probably use to map during the game at any time as they will keep looking at all assets even if some have been deleted.
http://www.gmlscripts.com/script/Resources/Management/
EDIT: alternate script to GMLscripts map_objects
Code:
///st_index_object([restrict]); returns ds_map. can restrict to given object type
/***************************************************
Generate ds_maps of resource name/index pairs.
returns map
Created by Salvakiya
***************************************************/
var map = ds_map_create(),
restrict = noone;
if argument_count==1 {
restrict = argument[0]
}
//Objects
var i = 0;
if restrict == noone{
while object_exists(i){
//restrict the map to given type
if object_is_ancestor(i, restrict) then map[? object_get_name(i)]= i;
i++;
}
}
else
{
while object_exists(i){
//index all objects
map[? object_get_name(i)]= i;
i++;
}
}
return map;
Last edited: