Checking if a value of a variable is one of a list of values
Posted: Tue Nov 30, 2021 2:00 pm
Sorry for the newbie question, but how do I do separate a list of values from the logic?
Currently, if I need to compare a variable to a list of values, I do something like this:
I would like to do something like:
Ideally would be if the list could be taken from a TEXTURES file. As you know, there can be multiple TEXTURES files in the mod folder, and I have organized my textures into separate files like TEXTURES.wood.txt, TEXTURES.ice.txt, TEXTURES.stone.txt, etc. So, ideally would be to read file TEXTURES.wood.txt, get all lines that begin with "Texture" (for example: Texture "WOOD1", 512, 512), and get the names in quotes (in the example above: WOOD1) from there.
But if it is impossible, or too complicated, I would be content with just defining a list of values within the zscript file itself, just separately from the logic.
Currently, if I need to compare a variable to a list of values, I do something like this:
Code: Select all
string TextureName;
TextureName = TexMan.GetName(foo);
if (TextureName == "WOOD1" || TextureName == "WOOD2" || TextureName == "WOOD3" || TextureName == "WOOD3")
Code: Select all
string TextureName;
bar = ... // a list of strings like WOOD1, WOOD2, etc
TextureName = TexMan.GetName(foo);
if (TextureName == bar) // where bar is any value from the list
But if it is impossible, or too complicated, I would be content with just defining a list of values within the zscript file itself, just separately from the logic.