logix1390 Posted June 6, 2018 Share Posted June 6, 2018 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. Quote Link to comment Share on other sites More sharing options...
woodenduck Posted June 6, 2018 Share Posted June 6, 2018 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 2 Quote Link to comment Share on other sites More sharing options...
logix1390 Posted June 6, 2018 Author Share Posted June 6, 2018 Makes sense now. thank you woodenduck Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.