Implementing a CASE statement construct

I would appreciate any hints/pointers on attempting the following…

I need to evaluate a set of parameters and do an action based on the results, using both system properties & random inputs compared to fixed criteria…
I would like to set a parameter based on some other parameters… In old school programming, I would have used something like a CASE statement or nested IF/THEN/ELSE. EXAMPLE:
CASE
A == “A” - Send ALPHA to Location X
A == “B” - SEND BRAVO to Location X
(A == “C”) && (die1 >= die2) Send CHARLIE to Location X
(A == “C”) && (die 1 < die2) Send DELTA to Location X
END CASE

I have resolved to first calculate a single property based on the input properties and random elements and then use that property to control Send to Location Result.

However, I’m struggling with how to set a property using something equivalent to a CASE or nested IF/THEN construct…

It appears I could use something like a Dynamic Property with an expression builder that looks something like
TYPE “Set Value Directly”
PROMPT {(($A$==“A”) ? (Red) : 0)}

However, it errors out… $A$ is set correctly…

Also, I don’t want to set a value if it’s false, but leave it alone…

Any hints or pointers to modules that do this as an exemplar would be appreciated…

Except for simple cases, I use triggers. For example, to implement if x==1 code1, else if x ==2 code2 else if x==3 code3, I would create 3 triggers, which all respond to the same key command. Each trigger would have a property test: x==1, x==2, and x==3, and each would execute its commands: code1, code2, and code3. For nested statements, triggers would call other triggers.

1 Like

You shouldn’t be using the $A$ construct in Beanshell expressions (anything within curly braces, {}), except within a match expression for a GKC (if you were to use it anyway, it needs to be enclosed in quotes, so “$A$”==“A”). Assuming your Dynamic Property is called “x”, have you tried

{(A == "A" ? Red : x)} ?
That should set x to the value of Red if A is “A”, otherwise set it to its current value (i.e., no change). (Those parentheses should be superfluous, but I’ve run into errors with ternary expressions when I don’t enclose them in parentheses, and they certainly won’t hurt.)

1 Like

Thanks much guys, your hints guided me to get it working!

The code sample was what I needed, I didn’t realize I should use $$ inside of {} AND that I could simply insert the property name as the (false) portion… Been away from coding too long and my reflexes are rusty…