Created
June 6, 2015 15:10
-
-
Save zerosalife/f13eb62bf7bd57799db6 to your computer and use it in GitHub Desktop.
Create a Dictionary of Lists in Unity JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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