Jump to content

Use value of i in for loop


ryreh

Recommended Posts

Hello! 
In Attribute Wrangle I did:
vector x = {1,2,3};

int i = 1;

vector y = set(x1); // this makes @y={1,2,3}
Can I did it in other way to get the same result?:
vector y = set(x); // here x should became x1

 

Link to comment
Share on other sites

set() is how you populate a vector variable. It requires 3 values. You don't use set() to set one variable equal to another, just use the equals symbol =

// braces are used only for constants and can not support variables.
vector v = {1,2,3};

// set() is used for constant or variable style vector construction.
float x = 1.0;
float y = 2.0;
vector v = set(x,y,3.0);

// equals is for assignment.
x = y;
vector v = set(x,x,x);

 

Edited by Atom
Link to comment
Share on other sites

40 minutes ago, Atom said:

set() is how you populate a vector variable. It requires 3 values. You don't use set() to set one variable equal to another, just use the equals symbol =


// braces are used only for constants and can not support variables.
vector v = {1,2,3};

// set() is used for constant or variable style vector construction.
float x = 1.0;
float y = 2.0;
vector v = set(x,y,3.0);

// equals is for assignment.
x = y;
vector v = set(x,x,x);

 

I badly explained what I want,sory(
Here is what I meant:
I have vectors variable which have numbers in theirs names (x1,x2,x3 etc). And I have an integer variable/variables (i = 1,2,3 etc.). 
So my goal is to call the vector variable in a loop:
for (int i =1; i<4; i++){

vector y = set(x`i`)  - here I want Houdini commits this expression like "set(x1)" and value of x1 should assained to y.

Link to comment
Share on other sites

No need for any of that then.

vector x1 = set(1,2,3);
vector y = x1;

I don't think you can construct a variable name as a string and then operate upon it as if it was a variable. You may want to review the VEX language syntax and functions.

Edited by Atom
  • Like 1
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...