You are not logged in.
Pages: 1
I've seen this question on the GMC quite a few times and I thought I might try to create a script for it. I made this, with the help of a friend. It returns the sprite index of the sprite with the name of argument0. This was the fastest way that I could think to do it.
/*
** Usage:
** sprite_get_from_string(spritename);
**
** Arguments:
** argument0 = the name (a string) of a sprite
**
** Returns:
** the sprite_index of the sprite with that name, -1 if no sprite with that name was found
**
** Notes:
** No special notes
**
*/
var spr,spr_n;
spr=sprite_create_from_screen(0,0,1,1,0,0,0,0) //creates a new sprite
for (spr_n=0;spr_n<spr;spr_n+=1){ //repeats for all sprites
if sprite_exists(spr_n){ //if it exists
if sprite_get_name(spr_n)=argument0{ //if its name is argument0
sprite_delete(spr) //delete the created sprite
return spr_n; //return the number of the sprite
exit;}
}
}
sprite_delete(spr) //delete the created sprite
return -1;
Is there any way to make this faster, more efficient, or better in general?
What do you think of the uses of the actual code too?
Oh, also, if I haven't formatted my code, I'm sorry, my usual way of formatting it is very messy, so I hope I've done it right.
Pages: 1