GrayHare Posted July 23, 2015 Share Posted July 23, 2015 (edited) Hi there, I am a newbie in vex and tried to start from some basic computing to learn it. In this case I tried to recreate a computing: $PT/$NPT and give this value to @Cd. I tried three different ways but only one way works. float pt; float npt; float cr; pt = @ptnum; npt = @numpt; cr = pt/npt; @Cd = {0,0,0}; @Cd.x= cr; Follows are not working. @Cd = {0,0,0}; @Cd.x = @ptnum/@numpt; @Cd = {0,0,0}; float cr; cr = @ptnum/@numpt; @Cd.x = cr; Looks like I can't use global variables to compute directly. Any explains? Thanks! Gu Problem.hip Edited July 24, 2015 by GrayHare Quote Link to comment Share on other sites More sharing options...
magneto Posted July 23, 2015 Share Posted July 23, 2015 I didn't check everything but VEX is case sensitive, @Ptnum should be lower case. Quote Link to comment Share on other sites More sharing options...
GrayHare Posted July 23, 2015 Author Share Posted July 23, 2015 (edited) I didn't check everything but VEX is case sensitive, @Ptnum should be lower case. thanks for your mention ryan. Edited July 23, 2015 by GrayHare Quote Link to comment Share on other sites More sharing options...
fathom Posted July 23, 2015 Share Posted July 23, 2015 the first one would work and others would fail because of types. one drawback with vex handling multiple types is that it sometimes picks the wrong one when it's ambiguous. ptnum and numpt are integers. so int/int yields and int. since ptnum is less than numpt, it will always be 0. your first one works because you first make float versions of your ptnum and numpt values and then divide using floats so you get a float result. try: @Cd.x = float(@ptnum)/@numpt; that will cast ptnum to a float for the division which will then yield a float result. when you use vectors, this gets more annoying. some functions return multiple types and will pick the type based on the other types involved. for example: v@N = noise(v@P); # returns a vector v@N = noise(v@P)*2; # returns a float (which then promotes to a vector of all the same value) 1 Quote Link to comment Share on other sites More sharing options...
anim Posted July 24, 2015 Share Posted July 24, 2015 yes, types are important, but you can as well use automatic promotion to your advantage so if you want to get number 0-1 you would want to do $PT/($NPT-1) (as @PT starts at 0) so while you can do: @Cd.x = float(@ptnum)/(@numpt-1); you can simply type: @Cd.x = @ptnum/(@numpt-1.0); as 1.0 is float it will evaluate everything as floats automatically 1 Quote Link to comment Share on other sites More sharing options...
GrayHare Posted July 24, 2015 Author Share Posted July 24, 2015 I got it! I thanks Miles and Tomas, your explainings are very straightforward:) 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.