Jump to content
Alexandre

Print an array element for debugging

Recommended Posts

Hi everyone !

I'm learning VEX (from CGwiki and Entagma) and I don't understand why the result of the following code is 0 whereas it should be 3... what did I misunderstand ?

int myarray[] = {2, 3, 4, 5};
int foo = myarray[1];
printf("%i \n",i@foo);

Thanks !

Alexandre

 

 

odforce_forum.JPG

Share this post


Link to post
Share on other sites

you print out i@foo which is an attribute that does not exist so it gets initialized right in the printf() and default initialization is 0. you want to print your variable foo

Share this post


Link to post
Share on other sites

Another question which is a step further... but still low level

I want to access to a specific float attribute called d (related to a distance), I have tried attrib, point, pointattrib... I don't understand how to access to the nth value of d. Moreover I don't understand what mean the integer "&success" in the help function

In the example in attachment I would expect to get 1.49176 instead of 30 times "0.0000"

thanks !

Alexandre

odforce_forum2.JPG

Share this post


Link to post
Share on other sites

You should give up using prints with vex, just use the spreadsheet as your print out. There is no need to fetch the point value of @d from the point that you are running over. Just use @d. Vex is a sand box. when you enter the wrangle, the information about points is made available to the wrangle, kind of like a copy. You can operate upon those entries, then when you exit the wrangle internal housekeeping remaps everything to make the output work correctly. This prevents you from performing certain operations typical in a top-down programming language. It also prevents you from messing up indicies.

Try using two wrangle, one to add new points and the other to review or revise those points.

You are trying to print @d for point #1.

Try...

if(@ptnum==1) print("%02d\n",@d);

You should not ignore the success flag either. Pass a valid variable, not 0.

Also I don't think primuv returns a point that you can just pass to addpoint. It returns the value at the UV coordinate. This would cause all the other operations on that point to be suspect. Your getting 30 zeros because the pointattrib is failing, you are not examining success and a zero is returned just as the documentation states.

Share this post


Link to post
Share on other sites

concerning primuv, this is not from me but cgwiki, it seems to work as I am projecting points on my semi-phere as shown in attachment

odforce_forum3.JPG

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

×