Jump to content
Sign in to follow this  
ryreh

Use value of i in for loop

Recommended Posts

ryreh    0

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

 

Share this post


Link to post
Share on other sites
Atom    516

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

Share this post


Link to post
Share on other sites
ryreh    0
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.

Share this post


Link to post
Share on other sites
Atom    516

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×