Skip to content

Instantly share code, notes, and snippets.

@zerosalife
Created June 6, 2015 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerosalife/f13eb62bf7bd57799db6 to your computer and use it in GitHub Desktop.
Save zerosalife/f13eb62bf7bd57799db6 to your computer and use it in GitHub Desktop.
Create a Dictionary of Lists in Unity JavaScript
#pragma strict
import System.Collections.Generic;
// White space matters.
var table:Dictionary.<String,List.<int> > = new Dictionary.<String,List.<int> >();
// Fill our table with Lists containing ints using Arrays to intialize
// the Lists.
table["a"] = new List.<int>([1]);
table["b"] = new List.<int>([2]);
table["c"] = new List.<int>([3]);
function Start () {
// Iterate over the Keys in our Dictionary.
for(var str:String in table.Keys) {
// Get the value for our Key.
var value:List.<int> = table[str];
// If the Key is our desired Key, append to its list.
if (str == "c") {
value.Add(4);
}
// Print the first item in each of the Lists.
print(value[0]);
}
// Print the appended item to see that it worked.
print(table["c"][1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment