ArrayList on Unity iphone?

Does Unity iphone support ArrayList ?

I have the e following piece of code working fine on pc but on my Mac the list contains nothing…(and the print doesn’t print)

It could be because I gone through on the mac and statically typed all the variables but could this have affected the arrayList?

function CreateUniqueRandomArray(desiredArrayLength,min,max) {
	
	//desiredArrayLength=max-min;
	
	//error check if the array is too long for the amount of numbers. It will get stuck in loop.
	if(desiredArrayLength>((max-min)))
		{
			//error
			Debug.LogError("Array is too long for the amount of numbers given to fill it");
			//set it to the max only. so it wont crash
			desiredArrayLength=max-min;
		}
	
	var list : ArrayList =  new ArrayList(); 
	list.Capacity=desiredArrayLength;
	while (list.Count < desiredArrayLength) 
	{ 
		var number :int= Random.Range(min, max); 
		if (!list.Contains(number)) 
			{
			list.Add(number); 
			print("One added to list");
			}

	} 
	//print out the list of numbers in the log
	var logString : String = "UniqueRandomNumbersList: "; 
	//prints okay!
	for (var num : int in list) { 
		logString += num + ", "; 
		//doesnt print!
	} 
	Debug.Log(logString); 

	return list;
}

Yes, it supports ArrayLists.

If it’s working on the PC, then I it’s in regular Unity, where such variable declarations will work.

JavaScript for Unity iPhone has some different rules for the declarations I believe. I don’t have the exact solution, as I don’t use JS with Unity. I know it works in C#, and I don’t see why ArrayLists wouldn’t work, there is jsut some little tweaking which must occur.

Sorry for the lack of an answer.

whats the output if you replace the last section with this?

Debug.Log("List length: " + list.Length);
for (var num : Object in list) {
      logString += num.ToString() + ", ";
      //doesnt print!
   }

not sure if array lists have Length, use the right one otherwise. I don’t use arraylists at all. Either Array or HashTable or LinkedList

also I’m not sure if you are meant to mess with list.Capacity that way.

Cheers guys but I figured it out.

I was basically setting the array to contain ‘nothing’ earlier in the code. Clever me :slight_smile:

The code attached all works fine.

Cheers guys but I figured it out.

I was basically setting the array to contain ‘nothing’ earlier in the code. Clever me :slight_smile:

The code attached all works fine.