Jump to content

How to use references properly


mediawreckage

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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 

Link to comment
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...

Link to comment
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

Link to comment
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.

Link to comment
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 

Link to comment
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.

Link to comment
Share on other sites

  • 2 months later...

Hey anim, hey noobini. Thanks for the reply (I know it's a little late)!
I figured it out myself and yes, while writing the post on top I lagged the understanding that I had to use the set function to declare my vector.

But still this became quite fruitful, as I learned today about the different meanings of ' ' and " " which I took for the same until today.

- - -

And answering my second question here (how to make use of the second input of the wrangle, instead of hardcoding the relativ reference):
A simple approach is to take the boundingBoxCenter of the second input:
 

vector inp_boxCenter = getbbox_center(1);

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...