Question marks and colons

Hi, i have found this piece of code, for what is it question marks and colons? :slight_smile:

float horizontalStrafe = Input.GetAxis(“Horizontal Strafe”) < 0 ? -1f : Input.GetAxis(“Horizontal Strafe”) > 0 ? 1f : 0f;

Hey… it’s another sytax for ‘shorthand’ IF statements, to set a variable.

In pseudo code:

if (this < 0) {
variable = “one”
} else {
variable = “two”
}

could be written as:
variable = (this < 0) ? “one” : “two”

The ? denotes then end of the question/if statement
The : denotes the split between both options.

Conditional operator. See:

http://msdn.microsoft.com/en-us/library/ty67wk28.aspx