Jump to content
Sign in to follow this  
mediawreckage

How to use references properly

Recommended Posts

I would like to get some basic understanding on how to use attributes,  channels, references in vex properly.

I'd like to understand in detail why this works:
 

v@planepos = {`chs("../grid1/tx")`, `chs("../grid1/ty")`, `chs("../grid1/tz")`};

While this throws an error on the fourth line:
 

f@planeTx = ch("../grid1/tx");
f@planeTy = ch("../grid1/ty");
f@planeTz = ch("../grid1/tz");
v@planepos = {@planeTx, @planeTy, @planeTz};


And could I avoid the relative references at all?
I am aware that the attribute wrangle has some optional inputs, how could I make use of them to achieve the same result as my first example?

something like: v@planepos = attrib(1, 'Center')

 

 5ecd7cee9ec1b_Screenshot2020-05-26at22_32_39.thumb.png.6df3dec5702c79439c24d084143680eb.png

Share this post


Link to post
Share on other sites
Posted (edited)
float tx = ch("../grid1/tx");
float ty = ch("../grid1/ty");
float tz = ch("../grid1/tz");
v@planepos = set(tx,ty,tz);

adding the "@" symbol means your exporting/creating an attribute
You don't need that for variables that are only used inside your code, eg: you don't need f@planeTx, instead float planeTx
To create a vector from 3 floats, use the set() function
... and forget about backticks (`) that's evaluating expressions (hscript), nasty stuff!

Edited by bunker

Share this post


Link to post
Share on other sites
Posted (edited)

don't {} brackets DEMAND literals only ?

ie. absolutely no formulas/variables, fancy mancy anything in there, just pure literals like 0.123, 999

so

@P += {0,1,0}; works fine

but even with just pure literals

@P += {0,1+1,0}; would fail coz of a formula in there so you see how strict it is.

 

EDIT: oh hey...just found that

@P += {0,`1+1`,0}; actually does the additiion !! wohoo...

Edited by Noobini

Share this post


Link to post
Share on other sites
5 hours ago, Noobini said:

EDIT: oh hey...just found that

@P += {0,`1+1`,0}; actually does the additiion

yes, but

5 hours ago, Noobini said:

!! wohoo...

no

no reason to celebrate or abuse this beyond the basic need of injecting static text into a snippet, as Julien mentioned text within `` simply evaluates hscript expression as in any other houdini parameter, that expression returns value which is injected as a text into the snippet, which then gets compiled and executed, so your {0,`1+1`, 0} gets evaluated to {0,2,0} and that gets compiled, and because all of them are constants it will work. Also this is evaluated only on 1st frame so no time dependent expressions or hscript channel references should be directly injected using `` into the snippet text, but it's useful if you want to generate the code or parts of it using static expressions 

Share this post


Link to post
Share on other sites
1 minute ago, anim said:

yes, but

no

no reason to celebrate or abuse this beyond the basic need of injecting static text into a snippet, as Julien mentioned text within `` simply evaluates hscript expression as in any other houdini parameter, that expression returns value which is injected as a text into the snippet, which then gets compiled and executed, so your {0,`1+1`, 0} gets evaluated to {0,2,0} and that gets compiled, and because all of them are constants it will work. Also this is evaluated only on 1st frame so no time dependent expressions or hscript channel references should be directly injected using `` into the snippet text, but it's useful if you want to generate the code or parts of it using static expressions 

just wanna see if a simple addition would work...me trying something is better than me doing nothing...

Share this post


Link to post
Share on other sites
3 minutes ago, Noobini said:

just wanna see if a simple addition would work...me trying something is better than me doing nothing...

just tried to explain what really happened there and why it "worked" also why it can be deceiving or dangerous, if you don't need the explanation or warning about the dangers and also usefulness of this method, you can ignore

Share this post


Link to post
Share on other sites
10 minutes ago, anim said:

just tried to explain what really happened there and why it "worked" also why it can be deceiving or dangerous, if you don't need the explanation or warning about the dangers and also usefulness of this method, you can ignore

well if you wanna say I abuse things simply because I try things, okay then, not everyone has vast knowledge as you.

Share this post


Link to post
Share on other sites
18 minutes ago, Noobini said:

well if you wanna say I abuse things simply because I try things, okay then, not everyone has vast knowledge as you.

I didn't accuse you personally of abusing it, just warned not to abuse this newly found "feature" and explained why, simply cause it's not what it may seem and I've seen many cases, where it was abused to get the seemingly working result, mostly because of misunderstanding of what is actually happening, see the first post for example, where it simply seemingly works when there are injected hscript references, etc., hence the need for explanation 

Share this post


Link to post
Share on other sites
3 minutes ago, anim said:

I didn't accuse you personally of abusing it, just warned not to abuse this newly found "feature" and explained why, simply cause it's not what it may seem and I've seen many cases, where it was abused to get the seemingly working result, mostly because of misunderstanding of what is actually happening, see the first post for example, where it simply seemingly works when there are injected hscript references, etc., hence the need for explanation 

ok, cool...and I've always appreciated your input/help. Just that the comment riled me a bit at first read ....calmed down now.

Thanks again.

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
Sign in to follow this  

×