Jump to content
Sign in to follow this  

simple vex question

Recommended Posts


I am a complete noob at vex but I am trying to learn it.

I have this here:
@id = 1;
@id = rand(@ptnum);

why is it that this results in the id being 0...why does the random function not execute as it should?

If i give my own variable like this:

@myId = 1;
@myId= rand(@ptnum);

Then it works perfectly... I am a little confused on why one works but not the other.

Thank you.


Share this post

Link to post
Share on other sites

I think it's because "id" is recognised automatically in vex as an integer attribute. As the rand() function returns a float, this gets truncated, resulting in 0. If you explicitly cast your "id" attribute as a float, I think you'll get what you're after.

Try f@id = rand(@ptnum);

The reason it works for @myId is because user defined variables default to floats if not explicitly cast. If you change it to i@myId = rand(@ptnum) it will return 0 for the same reason as stated above. 

Hope that helps. 



  • Like 2

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