Condensing If Statements
Shadecerule
05 Feb 2020, 23:35Is it possible to condense If statements like the following:
if (action = "Run" or action = "Escape" or action = "Flee")
...into something like this?
if (action = "Run", "Escape", "Flee")
And if so, how?
mrangel
06 Feb 2020, 09:21The most efficient way would be using a switch block.
switch (action) {
case ("Run", "Escape", "Flee") {
// code here
}
}
You can do a switch block with only one case; though in your example I suspect you will want one for each possible action.
mrangel
06 Feb 2020, 09:37You could alternatively do if (ListContains (Split("Run;Escape;Flee"), action)) {
or if (Instr ("Run;Escape;Flee", action) > 0) {
.
But if your code is going to continue with else if (action = ...
, then you should definitely be writing a switch
block with one case
for each option.