Get variable by string

I want to make a for loop in bp to assign enemy1, enemy2, enemy3… into enemy array using incremental suffix. How do I get this done using this way, in as3 it’s something like,

for(x=0; x<size; x++){
 enemy[x] = getchildbyname("enemy" + x);
}

Hope the below pic can show u what I need =)
Thanks!

What type is your array? Just a string array for the names?
Have you tried using a for loop and appending the Index to
the String “Enemy”?

You can use “Build String from Int” to just add the int to
the String you want or just convert it to an int like you
showed.

I don’t really get your problem since you already drawed
your solution which should work :X

Please describe the problem in more detail. I didn’t get what exactly do you want to do!!!

well i have list of float variables (EQ1, EQ2, EQ3…), after some calculation of every each float, now I want to put it into an array call EQ. this is what I want to do but i have no idea how to make it work.

I was thinking to assign all the variable (EQ1, EQ2, EQ3…) into the EQ array by using for loop, and then set array element (as you can see the pic above) corresponding to the float variable name. (e.g. EQ[0] = EQ1, EQ[1] = EQ2, EQ[2] = EQ3…), the problem is the “Set Array Elem” param only takes 1 constant value. Let’s say I take EQ1 and plug into the Item param), in the next iteration, my EQ[1] = EQ1 which is the problem right here.

What I want is to assign EQ2 into my 2nd index (EQ[1]) of array instead of keep assigning the same value. I want to change the item param dynamically as the iteration going on. So I draw the pinky square box there to see if there is some function allow me to use string to represent my variable name so I can change the suffix of 1,2,3,4… based on the index of the loop, and this function will combine string of “EQ” and “1” together and formed “EQ1”, so that EQ2 in next loop. Hope you can understand, my english is very bad =O

I think what you’re looking for is get enemy by class and switch through your types.

I honestly see no reason to do it by string as all it would potentially do is cause weird bugs.

Also in your case you’re using floats… not sure what the point is of getting a float by string as they are pure numbers.

Why don’t you use the “Add” function of the array. It allows you to add element at the end of array, no matter the array is empty or not.

Gonna try this tmr, really thank for your help I guess I know where the problem is already!

if the number of enemy is fixed, you don’t need to use “set_array_element” function or assigning a name for each of them. Simply use “Add” function to put the eq1, eq2, … inside the EQ array, and when ever you need their value, use “Get” function of array to get value of the element by index.

You;re right, i should construct the array with all element inside first then update through the loop, thank you it’s working now. =]