I am trying to add an item in an array only once a concept witch seems to be to complicated for me.Every time i add an item to an array it continuously loops , adding the item.
I want to know how to add the item only once but without using the if function :
if(array.length > 0)
array.Add(item)
The array that i am using is dynamic and if i use a true/false statement it always adds at least 16 copies of the same item.
An example code would be nice.
var myArraylist : ArrayList;
var item : int;
var case : string;
function Start (){
myArrayList = new ArrayList();
ChangeItem(case);
}
function ChangeItem(var caseValue : string){
if(caseValue == "a"){
myArrayList.add(1);
}
if(caseValue == "b"){
myArrayList.add(2);
}
if(caseValue == "c"){
myArrayList.add(3);
}
case = "";
}
//You can call the ChangeItem at any time, but because case is reset to an empty value, It wont add anything to the array, making it only add once.