...[index].Pos.Y += (up) ? step : -step;
General question here. I have NO idea how I'd begin to look this up so if someone could explain the (up), ?, and : portions of this that would be great. up is a bool that's passed in, but why's it in () and how's it used to perform what seems like a math calculation, and I've never encountered the ? or : used like this before. step is how many units to move a vertex I know but the rest is confusing the hell out of me.
Edit: wait. is it sort of an inline if-then-else statement? if up is true, then use a positive step value, otherwise (:) use a negative one?
What's this? .Pos.Y += (up) ? step : -step;
-
- Posts: 11
- Joined: Mon Mar 14, 2011 10:48 am
Re: What's this? .Pos.Y += (up) ? step : -step;
you can write it also as:
yes it is a if-than-else statement, sometimes is usefull using it. usually is not used very often.
Code: Select all
if(up)
{
[index].Pos.Y +=step;
}
else
{
[index].Pos.Y -= step;
}
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
I like this statement. I often use if for debug printing, e.g.
or in return statements, e.g. in getter methods
Code: Select all
printf("some string=\"%s\"\n",someString!=NULL?someString:"NULL");
Code: Select all
myObject *getObjectAtIndex(u32 index) {
return index<objectArray.size()?objectArray[index]:NULL;
}
Dustbin::Games on the web: https://www.dustbin-online.de/
Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
Dustbin::Games on facebook: https://www.facebook.com/dustbingames/
Dustbin::Games on twitter: https://twitter.com/dustbingames
-
- Posts: 11
- Joined: Mon Mar 14, 2011 10:48 am
If i'm not mistaken, it's also possible to use it like this
I cant access codepad atm so i cant check it. If i remember correctly one can get some amusing behaviours from different compilers when using the ternary operator like this.
Code: Select all
int x=5, y=6;
bool storeinx=true;
(storeinx?x:y) = 4;