Understanding a logical expression

What is this expression saying? Specifically what part do the numbers at the end of each statement represent? Variables? True/False?


This is from Twilight Struggle. Influence = the number on the counter; Control = the counter image (controlled or uncontrolled).

The syntax is if(expression, result if expression is true, result if expression is false).
So, that above expression is saying if Influence is equal to 0, return 0; otherwise, if Control is equal to 1, return 2; otherwise, return 1.

Or, see Mark’s more complete explanation, just below (which appeared a split second after I posted; LOL).

1 Like

The syntax is: If(condition, outcome_if_true, outcome_if_false)

So in long form, the TS example means:
If the number on the counter is zero (or blank), make it zero.
Otherwise, flip Control between 1 and 2 (presumably these are Levels in an image Layer).

If you are writing If statements, consider the ternary operator instead. It is more concise and much better for chaining conditions. The TS example would look like this:
{Influence == 0 ? 0 : Control == 1 ? 2 : 1}

Thanks. Your examples make it much clearer.

To your parenthetical - yes the switching between “1” and “2” has to do with Levels in an Image Layer. Which makes your tertiary operand example make more sense to even someone who doesn’t understand the language, since I at least can see a difference between a “?” and a “:” .

Just to be a bit pedantic but ?: is the ternary conditional operator, not the tertiary operator–so called because it takes 3 operands, rather than the typical binary operator, which only takes 2. (There are also unary operators, such as ! for negation.)

1 Like

Yes, it took me 10 minutes away from the computer but I eventually realised my error. Corrected.