Jump to content

Try Except in VEX alike in Python?

Recommended Posts

One thing that I miss from Python(Try / Except) or XSI ICE (First Valid) is the ability to check if some code returns errors and if so, do something else that is safer.

Is there a way to access the validity of something and if not do something else?


Edited by probiner

Share this post

Link to post
Share on other sites

Interesting..divide by zero is just zero and not an error.

float m = 100;
f@n = m/0;


Share this post

Link to post
Share on other sites

Vex is a highly multi threaded language, I think adding try-catch/except logic would seriously slow it down.
most value errors at least, will just return 0, as VEX is strongly typed. (like Atom Mentioned)

Rather than crashing the node, its probably better to compare your values to 0 in some cases (and if the expected value is non-0)

Share this post

Link to post
Share on other sites

I don't have issues with division by 0 and I get you remark about optimization- I was just wondering if there was some way of doing this that I was missing..

My main issue is with variable types and functions/nodes that might break due to have a bad evaluation. and as far I as know I can't do a check on the variable type, neither create a variable with auto, so I was just checking if I can assess it another way around, by letting it fail, but do something else when it fails.

Take this example, float array[] = set(value) will work for all the non-array float composites, float, vector3, vector4, matrix3, matrix4. But...

But... it doesn't work with Vector2 or Matrix2.

Which is an alternative route already because something like matrix + 1 doesn't work (adding 1 to each component), so I decided to flatten all out into an array of floats and iterate over them. But even that doesn't work with all types :/

float floatval = 1.23 ;
float floatarray[] = set(floatval) ;
f[]@floatarray = floatarray ;

vector vectorval = {4,5,6} ;
float vectorarray[] = set(vectorval) ;
f[]@vectorarray = vectorarray ;

matrix3 matrix3val = matrix3(ident()) ;
float matrix3array[] = set(matrix3val) ;
f[]@matrix3array = matrix3array ;

vector2 vector2val = set(7,8) ;
float vector2array[] = set(vector2val) ;
f[]@vector2array = vector2array ;

matrix2 matrix2val = set({0,1}, {2,3}) ;
float matrix2array[] = set(matrix2val) ;
f[]@matrix2array = matrix2array ;

If I could check for variable type I could do something else for vector2 and matrix2. This because I'm trying to build overload nodes.
I also don't see a way to build a function with signatures, do I need to use HDK for that?

I'm all over the place, but I'm trying to find the best way to go about maximizing an operation to the maximum number of data types...


Edited by probiner

Share this post

Link to post
Share on other sites

Hi, you could add the missing definitions of set() and include them? But that is probably not what you want.

Edit: I have tried one of the missing definitions:

float[] set (vector2 input)
    return array(input[0],input[1]);


Edited by ikoon

Share this post

Link to post
Share on other sites

You could use the function "attribtype" combined with "attribsize". Attribtype will say that the variable is a vector and attribsize will say how many components the vector have.




One issue that can come up is comparing a vector2 vs a vector4

Edited by ThomasPara

Share this post

Link to post
Share on other sites

yeah, ok I think I see what you mean now,

I would also love stuff like:

setpointattrib(0, attrib, @ptnum, point(0, attrib, otherSourcePt));

to work.. (I understand its ambiguous, but some auto casting of variables mid-code-line would still be nice) 

The functions from Thomas are workable :)
they will result in almost 200 lines of code to make all checks, the strongly typed way
(unfortunately I cannot share the code :/ ) 

Edited by acey195

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