Game Development Community

A mark question

by David Tan · in Torque Game Engine · 08/31/2004 (8:43 pm) · 2 replies

I am a newbie,I have a question,what do the mark "?" mean in the follow code:
Quote:
function turnRight( %val )
{
$mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

thanks.

#1
08/31/2004 (10:40 pm)
That's a special operator that comes from C, it's called the "conditional operator".

basically, it follows the form:

condition ? statement1 : statement2

what this means is that if "condition" is true, execute statement1, if "condition" is false, execute statement2.

In the example you gave, $mvYawLeftSpeed will be set equal to $pref::Input::KeyboardTurnSpeed if %val is non-zero and it will be set to 0 otherwise.

It's late, so rather than having me try to explain any further, here's a more comprehensive and possibly more confusing article from MSDN.

The Conditional Operator (? :)
#2
08/31/2004 (11:20 pm)
Thanks.