Greetings all,
Could I seek some education on a minor VEX casting matter please:
I was following a tutorial where the following VEX code was entered in the 'force total count' parameter of a SOP Scatter node. The task being to change the random seed every 7 frames and output a value between 20 and 30.
fit01(rand(floor($F*(1/7))), 20, 30)
When I looked at the code I was surprised it worked (coding newbie alert).
My understanding is that "(1/7)" would be an integer calculation - and therefore give 0 as a result. Subsequently the random seed value would remain static at 0. To my surprise, the output value does change every 7 frames as intended.
Testing the above code in a separate point wrangle outputting to a float attribute gives a static output of 0 as I expected. Changing the code to ("1.0/7") to force a float calculation fixes the issue, as expected.
So: why does the original code work in the context of the scatter node parameter, but not in the context of a wrangle?
Or... what am I misunderstanding here : )
With thanks
Casting confusion
1556 4 0-
- Mike_A
- Member
- 393 posts
- Joined: Aug. 2018
- Offline
-
- animatrix_
- Member
- 5100 posts
- Joined: Feb. 2012
- Online
That's because that's not VEX code but an hscript expression. AFAIK by default all numeric values are evaluated as floats unless you use the int() expression.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
-
- Mike_A
- Member
- 393 posts
- Joined: Aug. 2018
- Offline
Ah, understood. I realised that '$F' was a HScript variable - but I read somewhere that VEX would interpret that, and wrongly assumed it was a VEX statement.
That leads me on to a secondary question: There are some node parameter fields that are specifically marked as 'VEX expression'. Are all node parameter fields that are not so marked exclusively HScript?
That leads me on to a secondary question: There are some node parameter fields that are specifically marked as 'VEX expression'. Are all node parameter fields that are not so marked exclusively HScript?
Edited by Mike_A - Jan. 8, 2023 04:24:02
-
- tamte
- Member
- 9376 posts
- Joined: July 2007
- Offline
Mike_Ano VEX doesn't understand $F variable it has it's own @Frame binding (which for "convenience" can also now be used instead of $FF in parameters so it may be confusing)
I realised that '$F' was a HScript function - but I read somewhere that VEX would interpret that, and wrongly assumed it was a VEX statement.
while it's possible to use $F in VEX snippet, it's expanded into the string and injected in the code before it's compiled which happens only on the first frame so $F specifically wouldnt animate, but $FPS or other static variables would expand to the value so it would sort of work, as in the code it would be a hardcoded constant since the expansion happens before before the code is compiled
Mike_Aparameters can contain either numerical value or string
That leads me on to a secondary question: There are some node parameter fields that are specifically marked as 'VEX expression'. Are all node parameter fields that are not so marked exclusively HScript?
such value can be typed in manually or generated using either HScript Expression or Python Expression
for string parameters you can also inject HScript Expression inbetween raw text using ``
VEXpression parameters are just string parameters, with VEX syntax highlighting for conevenience
the string/text you write in there can also as mentioned be generated using HScript or Python Expression and once those expressions are evaluated you will get final string which is hopefully a valid VEX snippet code
this is then referenced by a node inside of that HDA that can evaluate such VEX snippet, usually Snippet VOP or Attribute Wrangle Core SOP
In other words when you are writing VEX in parameters you are literally just writing a string as far as parameters are concerned and could use HScript Expressions in the process, however you would need to be careful to not use any time dependent ones
Edited by tamte - Jan. 7, 2023 22:47:57
Tomas Slancik
CG Supervisor
Framestore, NY
CG Supervisor
Framestore, NY
-
- Mike_A
- Member
- 393 posts
- Joined: Aug. 2018
- Offline
-
- Quick Links

