I’m having touble finding info on generic lists for js online. The scripting reference has nothing on the and the tut video are for c# and the js tab under he tut video for js says that js is too different from the video, thus making a translation unusable. Somewhere else it said that js can’t use generic lists(might of been the scripting reference). However I finally found some code and understood what most of it does. I just need help understanding like 4 lines. Truth be told, I believe it’s a generic list but I’m not even sure.
#pragma strict
import System.Collections.Generic;
function Start ()
{
var list : List.<String>;
list = new List.<String>();
//Capacity is the number of elements that the List<T> can store before resizing is required
//Count is the number of elements that are actually in the List<T>.
Debug.Log("list capacity is " +list.Capacity);
Debug.Log("list count is " +list.Count);
Debug.Log("Adding 4 entries");
list.Add("Generics");
list.Add(" work");
list.Add(" in");
list.Add(" js");
list.Add(" too.");
Debug.Log("Note that now capacity is bigger than count");
Debug.Log("list capacity is " +list.Capacity);
Debug.Log("list count is " +list.Count);
//js cannot have foreach but can use for in
var sentence:String;
for( var word:String in list)
{
sentence +=word;
}
Debug.Log(sentence);
Debug.Log("list.Contains(\"generics\") is " + list.Contains("generics"));
Debug.Log("list.Insert(5, \" Unity js rocks !\");" +" inserts a new item at the end of the list");
list.Insert(5, " Unity js rocks !");
Debug.Log("Let's check it");
sentence = "";
for( var word:String in list)
{
sentence +=word;
}
Debug.Log(sentence);
//For more methods of List check out http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
//Or google c sharp List
}
line#9: Why does he need to create a new list when he already created it on the line above?
line#19: He says adding 4 entries but he adds 5, is it just a typo?
line#33: Exactly, capacity end up being 8 and count ends up being 5, but why? If they both started at 0, and then he added 5 things, why does capacity jump up to 8?
line#60: What does the 5 do? Does it add something after the 5 thing in the list which would be “too”, or does it add something that’s 5 entries long?
line#64: I commented this out and debuglog printed “Generics work in js too” twice. So I know what it does I just dont understand why.
Sorry for all the questions. I used to do that before but now I usually stick to figuring out everything on my own. The problem is that the info on this is scarce so I could use the help.