If I have something and want to check that it’s equal to either of many things is there a way to do so without using the or operator / rewriting the whole thing?
For example, let’s say I have a string and want to check if it’s equal to “left” or “right”, is there a way to do
switch ( inputString ) {
case "left":
Debug.Log("Left");
break; // this command sends execution to the switch block's closing brace, }
case "right":
case "RIGHT":
Debug.Log("Right"); // this line executes if inputString is "right" OR "RIGHT"
break;
default: // this is what is chosen if none of the above cases are a match
Debug.Log("Default");
}
I guess that counts as rewriting, but there’s not a built-in way to compare to one-of-many-things.
You could write a function that might look like:
function IsOneOf( check : Object, list : Object[] ) : boolean {
for ( var item : Object in list ) {
if ( check == item ) return true;
}
return false;
}