etudenc Posted July 25, 2012 Share Posted July 25, 2012 (edited) Would someone be kind enough to tell me why the top expression works but the bottom one doesn't? Am I supposed to format a user-defined variable differently inside a function? # working { return vector("[1, 2, 3]")[0] ; } #not working { float dirX = 1 ; float dirY = 2 ; float dirZ = 3 ; return vector("[dirX, dirY, dirZ]")[0] ; } I've tried all kinds of variations such as: return vector([dirX dirY dirZ]) ; (no commas) return vector(["dirX", "dirY", "dirZ"]) ; (added quotes around each variable) return vector([("dirX"), ("dirY"), ("dirZ")]) ; (quotes and parentheses) return vector("[(dirX), (dirY), (dirZ)]")) ; return vector("[(dirX) (dirY) (dirZ)]")) ; (no commas) return vector("[(dirX)], [(dirY)], [(dirZ)]") ; return vector("[dirX], [dirY], [dirZ]") ; but no go. Thanks for any pointers! Edited July 25, 2012 by etudenc Quote Link to comment Share on other sites More sharing options...
rafaelfs Posted July 25, 2012 Share Posted July 25, 2012 I'm no vex expert, but have you tried this? return vector([dirX, dirY, dirZ])[0]; Cheers Quote Link to comment Share on other sites More sharing options...
etudenc Posted July 25, 2012 Author Share Posted July 25, 2012 I'm no vex expert, but have you tried this? return vector([dirX, dirY, dirZ])[0]; Cheers Thanks rafaelfs, unfortunately I have but no luck. I'll edit my post to include the variations I've tried. Maybe in the process I'll land on the right one! Quote Link to comment Share on other sites More sharing options...
rafaelfs Posted July 25, 2012 Share Posted July 25, 2012 BTW, what are you trying to do? Quote Link to comment Share on other sites More sharing options...
anim Posted July 25, 2012 Share Posted July 25, 2012 (edited) this looks like Hscript try this { float dirX = 1 ; float dirY = 2 ; float dirZ = 3 ; return vector( "[" + dirX + "," + dirY + "," + dirZ + "]" )[0] ; } EDIT: but as rafael said, tell us what you are trying to do, you may get answer to your actual problem instead of jus little fix of your approach which may not be the most efficient Edited July 25, 2012 by anim Quote Link to comment Share on other sites More sharing options...
etudenc Posted July 25, 2012 Author Share Posted July 25, 2012 this looks like Hscript try this { float dirX = 1 ; float dirY = 2 ; float dirZ = 3 ; return vector( "[" + dirX + "," + dirY + "," + dirZ + "]" )[0] ; } EDIT: but as rafael said, tell us what you are trying to do, you may get answer to your actual problem instead of jus little fix of your approach which may not be the most efficient Thank you, that worked! I was a long way from the answer! I don't know if this is the most efficient way of doing things but for my current project I decided to create a control node (a NULL) so that I can add and centralize some parameters. Using some expressions in each parameter, I'm able to - specify two points on whatever geo is plugged in to a transform SOP - get their respective positions - find the direction (a vector) I want to normalize the direction but I got stuck trying to figure out how to normalize a value coming from a parameter so this is my roundabout way of making it happen. I tried passing the direction vector to a point attribute but the normalize node in the VOP SOP isn't giving me predictable results, so writing an expression seems like the next thing to try. Thanks again! Quote Link to comment Share on other sites More sharing options...
rafaelfs Posted July 27, 2012 Share Posted July 27, 2012 Thank you, that worked! I was a long way from the answer! I don't know if this is the most efficient way of doing things but for my current project I decided to create a control node (a NULL) so that I can add and centralize some parameters. Using some expressions in each parameter, I'm able to - specify two points on whatever geo is plugged in to a transform SOP - get their respective positions - find the direction (a vector) I want to normalize the direction but I got stuck trying to figure out how to normalize a value coming from a parameter so this is my roundabout way of making it happen. I tried passing the direction vector to a point attribute but the normalize node in the VOP SOP isn't giving me predictable results, so writing an expression seems like the next thing to try. Thanks again! Let me see if I understand: having point A and point B, you want to be able to plug a transform SOP to point A so that it automatically moves to point B? Or do you just want to find the vector that would do such operation? Both cases are relatively ease to figure out with either a VOP SOP or a point SOP and some expressions... Cheers Quote Link to comment Share on other sites More sharing options...
Fabiano Berlim Posted July 27, 2012 Share Posted July 27, 2012 (edited) Variables inside strings should be called with $. Example: { float dirX=0; float dirY=1; float dirZ=2; return vector("[$dirX,$dirY,$dirZ]")[2]; } Edited July 28, 2012 by Fabiano Berlim 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.