Page 1 of 1

Redirect: C++ Question [Delete me!]

Posted: Sun Apr 01, 2007 2:18 am
by Dr.Bunshin
Hey all

I really dont mean to flood with useless noob threads, but could someone tell me where too look to understand how this works:

Code: Select all

v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
You can explain it if you want. I am sorry for my ignorance.

Re: Redirect: C++ Question

Posted: Sun Apr 01, 2007 2:40 am
by Granthus
Dr.Bunshin wrote:Hey all

I really dont mean to flood with useless noob threads, but could someone tell me where too look to understand how this works:

Code: Select all

v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
You can explain it if you want. I am sorry for my ignorance.
Basically it is saying

Code: Select all

if (event.KeyInput.Key == KEY_KEY_W)
    v.Y += 2.0f;
else
    v.Y += -2.0f;
Personally I would have used some parentheses (bracket things :)) to break it up and make it easier to understand - but it is making use of the 'shorthand' if statement format,

(logic test) ? TRUE : FALSE

Hope that helps

Granthus

Posted: Sun Apr 01, 2007 2:45 am
by khamill
v.Y (probably a y-axis cordinate) is getting incremented by the result of:

event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;

This says, if InputKey equals W, increment by 2.0, if not increment by
-2.0. The f on the 2.0 just stands for a floating point number.

Hope this helps.

Kevin

Posted: Sun Apr 01, 2007 3:51 am
by Dr.Bunshin
Hey guys!

Thank you so much! Thats about what I was thinking but you made it very clear. That is quite short short-hand if you ask me. :) Thank you again.