Problem when trying to save variable in another variable.

Hi.

I don’t know if its a bug, but when I try to save a variable to another variable in a loop, and change the first variable after, the second one gets change too.

Code:

//example

var variable : Array;

for (i = 0; i < 5; i++) {
	var variable2 = variable;
	variable.Clear ();
	//variable2 becomes empty too
}

“Variable” needs to get cleared because it will contain stuff to use in the next loop, but the stuff will be added this loop.

I’m sure I missed something… Any ideas?

Thanks

Arrays are passed by reference so you are not copying your array you are passing the address of it to the other. Now you have two variables pointing at the same spot.

You need to copy the whole array first and then clear it. Then variable2 will have the values.