Jump to content

simple vex question


logix1390

Recommended Posts

Hello,

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.

 

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

Cheers, 

WD

  • Like 2
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...