Reputation: 11
I'm working on a game using Ren'py, which is a visual novel creator which utilizes Python. I'm working on the character selection area, and I had a question about how to load an image, though my problem is more about if statements.
The character creation consists of four "questions". The player is asked which hair color they want, which is saved to a variable (i.e., if the player selects the "Blonde" option, the variable colorHair is set to equal 1, if "Black" is selected, the variable equals 2, and so on). The player is then asked for eye color, skin tone, and hair style, each of which is saved to a variable like the one above. In the end, I have four variables, colorHair, colorEye, styleHair, and colorSkin.
My original plan was to simply have a massive amount of if statements, which would be something like if (colorHair = 1 and colorEye = 1 and styleHair = 1 and colorSkin = 1) load image "1111.png" if (colorHair = 1 and colorEye = 1 and styleHair = 1 and colorSkin = 2) load image "1112.png" The above is pseudocode since I'm getting used to Python. I'm certain there's a simpler way to do this instead of just having 180 or so if statements. Is there a way to "combine" the variables into a string (i.e., if colorHair = 1, colorEye = 3, styleHair = 1, colorSkin = 2, make a string called "1312", and then pull up the image with the same name (1312.png)?) I'm very new to Python, so if anyone has any suggestions, I would greatly appreciate it.
Upvotes: 0
Views: 217
Reputation: 9726
Just convert your numbers to strings and join them:
filename = str(colorHair) + str(colorEye) + str(styleHair) + str(colorSkin) + ".png"
Upvotes: 1