21
Coding / [Solved] Variables in resource names
« on: February 24, 2010, 04:52:46 pm »
Well, I think that is barely worth making a topic for but I'm having a bit of trouble. I'm trying to figure out how I would go about using the value of a variable as part of a resource name, for example, say I have the variable 'ballcolor' (which can equal "G" or "R") and I have two sprites 'spr_bal_G' and 'spr_ball_R' how would go about using that variable to make the sprite dependent on the variable, I thought it would be something like this but it doesn't work:
draw_sprite(spr_ball_+string(ballcolor), 0, x, y)
So in the end the sprite is spr_ball_R.
Thats the best example I could think of off the top of my head (not a very good one though as you could simply do image_blend, but thats not the point). I'm relatively sure I've used +string()+ in a different programming language, I just need to figure out the GM equivalent, if there is one. I'm sure its rather simple, I've been looking around GM help for an answer but haven't come across one yet. Anyone have any ideas?
draw_sprite(spr_ball_+string(ballcolor), 0, x, y)
So in the end the sprite is spr_ball_R.
Thats the best example I could think of off the top of my head (not a very good one though as you could simply do image_blend, but thats not the point). I'm relatively sure I've used +string()+ in a different programming language, I just need to figure out the GM equivalent, if there is one. I'm sure its rather simple, I've been looking around GM help for an answer but haven't come across one yet. Anyone have any ideas?