Using variable as part of an identifier

Hi!

So in my game I use conditional branches to check the percentage of HP, MP, etc and for example if the result is 50 the game will show a life bar only half full using a Show picture event. The thing is I have several HUD items (HP, MP, Exp, and a couple more) and it takes about 400-500 conditional branches to do it, so if I want to change the scale of the pictures, the position, or anything really I have to do it 400 times, which is very inefficient. 

My idea to solve this was to use the script call $gameScreen.showPicture and then using for example "HPvariable6" as the file name, where variable 6 would store the percentage of HP, so if the variable is 62, the game would look for the picture HP62.png and show it.

Any ideas to use the variable for part of the filename?

Thank you for your attention!


Edit: I might have explained myself badly. What I need to know is a way to combine a variable and text into an identifier. In the case of using "HPvariable6" as the filename, the HP would be static, meaning that no mater what variable 6 contains, the filename will start with HP. So if the variable 6 is worth 32, the filename will be HP32, while if the variable 6 is worth 60, the filename will be HP60.
you could place it in a common event. as for using a variable as an identifier. you cant really do that via events only what within the interpreter such as variable id or map id. you'd need to make a script. also ive found sometimes there are cases where you're trying to check for 2 variables at a time and to do that with just events youd need to make 2 conditional branches however. with the script option you can check them both at the same time


I.e. if $gameVariables.value(1) == 1 && $gameVariables.value(2) == 3 // checks for 2 variables at a time. check out the help file for operators. they can save loads of time.
you could place it in a common event. as for using a variable as an identifier. you cant really do that via events only what within the interpreter such as variable id or map id. you'd need to make a script. also ive found sometimes there are cases where you're trying to check for 2 variables at a time and to do that with just events youd need to make 2 conditional branches however. with the script option you can check them both at the same time


I.e. if $gameVariables.value(1) == 1 && $gameVariables.value(2) == 3 // checks for 2 variables at a time. check out the help file for operators. they can save loads of time.

Thank you very much for helping!


However, I don't think you got what I meant. I know the most efficient way is to do it via Script calls, but what I need to know is a way to combine a variable and text into an identifier. In the case of using "HPvariable6" as the filename, the HP would be static, meaning that no mater what variable 6 contains, the filename will start with HP. So if the variable 6 is worth 32, the filename will be HP32, while if the variable 6 is worth 60, the filename will be HP60.
var filename =  [COLOR= rgb(39, 42, 52)]"HP" + $gameVariables.value(6)[/COLOR]


[COLOR= rgb(39, 42, 52)]$gameScreen.showPicture ( ... using filename in the appropriate position ...)[/COLOR]
var filename =  "HP" + $gameVariables.value(6)


$gameScreen.showPicture ( ... using filename in the appropriate position ...)

Thank you very much!

Original thread: https://forums.rpgmakerweb.com/threads/using-variable-as-part-of-an-identifier.57584/