Jump to content
babbel

Unable to evaluate expression - basic if condition

Recommended Posts

Hello everyone,

 

I get this expression error but I can't figure why.

Can someone please tell what i'm doing wrong ? Or maybe it's not possible to do that in this field ?

if(ch("../depth")<5){ch("../depth")*4)+1}else{ch("../depth")*3)+1}

image.png.03ccff868a6cb39b3fdba5dd100526db.png

 

Thank you,

 

Baptiste

Share this post


Link to post
Share on other sites

I found the solution, it's because Houdini's expression has a kind of strange -if syntax-. "if (condition, then, else)"

Share this post


Link to post
Share on other sites

There is parentheses mismatch in the original expression, which will break any code.

If you want to use classic C-like if (cond) {statement} else {statement}, you need to open full editor via RMB menu and use multi-line expression (it is like a function body without function declaration itself):

{
    if (ch("../depth") < 5)
    {
        return ch("../depth") * 4 + 1;
    }
    else
    {
        return ch("../depth") * 3 + 1;
    }
}

What you used is if() expression function. I think it just wraps code above into something that is easier to use inside expressions. Although it evaluates both branches, I doubt if anyone ever had problems with it in practice.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×