Problem with IF statement

   1933   4   2
User Avatar
Member
63 posts
Joined: 9月 2014
Offline
I'm trying to take incoming points from a particle sim that has a hitnum attribute that is either 0 or 1. Inside the attribute wranger, No matter what I do I can't get the if statement to work. I get “synax error, unexpected if”

f@flame = if(@hitnum > 0, .25, 1);
Edited by eschwab - 2020年12月4日 13:11:40
User Avatar
Member
63 posts
Joined: 9月 2014
Offline
Well I found the answer on https://www.tokeru.com/cgwiki/index.php?title=JoyOfVex11 [www.tokeru.com]
The thing I don't get is why is this information not on sidefx's documentation? Or at least I couldn't find it in any of the vex functions or expressions.
The correct formatting would be as follows for anyone else that finds this.

if(@hitnum>0.0) {
f@flame = .25;
} else {
f@flame = 1;
};
User Avatar
スタッフ
186 posts
Joined: 11月 2019
Offline
You should find it under the vex section:
https://www.sidefx.com/docs/houdini/vex/statement.html [www.sidefx.com]

However it is indeed missing some other possible formatting you can use.

For example your code could be written in one or two lines as well:

f@flame = f@hitnum > 0 ? 0.25 : 1;

or

if (f@hitnum>0) f@flame = 0.25;
else f@flame = 1;
Edited by ati - 2020年12月5日 03:52:16
User Avatar
Member
63 posts
Joined: 9月 2014
Offline
Thank you for this. I did see that but it wasn’t as clear as you’ve made it. I guess the other format that I was using “if(statement, true, false)”is only for expressions and not in vex. Although that format is considerably easier than the C inspired one for vex.
I’m fairly competent at python but not C. Is the ? Operator a common use? I’ve never seen that before.
User Avatar
Member
27 posts
Joined: 3月 2020
Offline
I think the ? operator for ternary expressions in different languages is used more often than not. As much as I love python, I dislike how python does ternary. I prefer my true/false results to be grouped together as opposed to separated by the condition but just my two cents.
  • Quick Links