• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

string + string to variable ?

D

daprato

Guest
Hi GM people, having lot of fun, but I'm stucked here. I'm trying to join 2 string from 2 variable to make one variable that will represent a sprite name.

Let say that I have 5 sprites:
spr_icon
spr_car_1
spr_car_2
spr_car_3
spr_car_4

I have a scale that vary, used for other things
myscale = 1;

Now I want to draw tiled sprite base on this scale. So I thought about converting variables to string to combine them making my real sprite name
name1 = "spr_car_";
name2 = string(myscale);
mysprite=name1+name2
draw_sprite_tiled(mysprite, 0, x, y)

no matter how I want to pack my strings, it renders always my first sprite on my project : spr_icon

Thx
 

Zek

Member
What you need is asset_get_index, so basically like this:
mysprite = asset_get_index(name1 + name2);
 
Top