Expressions in channel field

   2051   7   0
User Avatar
Member
55 posts
Joined: March 2015
Offline
Hi

Can I write an if statement in a channel field so then I can set the value of that channel if the condition is true?

Thanks









https://vimeo.com/user43100796 [vimeo.com]
User Avatar
Member
2035 posts
Joined: Sept. 2015
Offline
Yes you can.

I don't know how to do it in Hscript

But if you set the expression language icon ( upper right hand corner of Parameter Window Pane in which your “channel field” resides ) to Python the code below will work.

In this case I have a box and the tx - “channel field” has the following code put in it.
the my_var_B variable is linked to the boxes ty position parameter.

So tx of the box will always be at position 2 unless ty is 2 which at the point tx becomes 4.


result = 0
my_var_A = 2
my_var_B = ch("ty")
if(my_var_A == my_var_B):
    result = 4
else:    
    result = 2
    
return result
Edited by BabaJ - July 30, 2016 15:29:17
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
Hi all.
This is really simple in Hscript.
something likes C++:
{
if(ch("/obj/torus_object1/transform1/ty") > 1)
return 1;
else
return 0;
}
Edited by Nima - July 30, 2016 15:38:09
User Avatar
Member
55 posts
Joined: March 2015
Offline
Thanks for the fast reply.

What about VEX?

I wrote this in the “n°of copies” channel in a copy sop but gives me error.

int x = ch("../Height/Bricks_in_height");
int result;
if (x%2 = 0)
{
   result = x/2; 
  
}
return result;

EDIT:
Ok I tried the Hscript one and it works, but why cant I just write in vex in channels but just in wrangles?
Edited by SteN - July 30, 2016 18:21:55
https://vimeo.com/user43100796 [vimeo.com]
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
You should put all of your code in a pair of brackets:
This means that:
{
int x = ch("../Height/Bricks_in_height");
int result;
if (x%2 = 0)
{
result = x/2;
}
return result;
}
For using VEX instead of Hscript See example file.
Edited by Nima - July 30, 2016 19:28:03

Attachments:
Modifying with VEX.hip (60.0 KB)

User Avatar
Member
55 posts
Joined: March 2015
Offline
Thank you so much.
So basically if I want to use vex in a channel field I have to put the code in pair of curly brackets?
https://vimeo.com/user43100796 [vimeo.com]
User Avatar
Member
471 posts
Joined: Nov. 2013
Offline
When you are in channel field for more than one line of code you should put your code in a pair of brackets.
Edited by Nima - July 31, 2016 05:51:39
User Avatar
Member
55 posts
Joined: March 2015
Offline
Oh ok now I got it
https://vimeo.com/user43100796 [vimeo.com]
  • Quick Links