Simchron Posted April 26, 2018 Share Posted April 26, 2018 Hi there! Is it possible to dynamically declare variables in a for loop with the index in the variable name? Current problem: I want to store primitives with similar normal angles into an array. The maximum number of arrays would be 4 (cardinal directions) but in most cases the normals head in only one direction. Thanks in advance. Cheers Quote Link to comment Share on other sites More sharing options...
acey195 Posted May 2, 2018 Share Posted May 2, 2018 (edited) its possible with H14 and up using the http://www.sidefx.com/docs/houdini16.0/vex/functions/setprimattrib function along with http://www.sidefx.com/docs/houdini16.0/vex/functions/sprintf for example float angleVal; string attribName; for(int i = 0; i < 4; i++) { attribName = sprintf("angleDir_%d", i); angleVal = i; //do your math here setprimattrib(0, attribName, @primnum, angleVal); } in H13 and lower, the attributes have to exist before the setprimattrib or setpointattrib etc are used, with H14 and up, it will generate it for you or you can store them directly as an array attribute, but in some cases it may complain if the sizes of the array are not the same (at least in Python I think) in vex that would look something like this: float angleVals[], angleVal; string attribName; for(int i = 0; i < 4; i++) { angleVal = i; //do your math here append(angleVals, angleVal); } f[]@outAngles = angleVals; Edited May 2, 2018 by acey195 1 1 Quote Link to comment Share on other sites More sharing options...
Simchron Posted May 4, 2018 Author Share Posted May 4, 2018 Hi Twan, thank you very much for taking the time and the detailed explanation. 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.