I first tried using an Array (just because I knew how to do it), but this didn’t go well at all. From what I gather, using a Hashtable is the best way to go about this - is that correct?
If so, does anybody have an example / link /advice they could show me that explains how to go about setting this up in Unity? I’ve followed the link to the Microsoft page via the Unity docs, but without a Unity/JS example to follow I didn’t really know where to start with it.
I have a text file with one word per line (~75k words), though I can edit this so that it has any necessary code around each word if that makes it easier. I don’t need to do anything too fancy with this, just check whether a given word is in the list or not.
var mywords = {"apple":"fruit", "monkey":"animal"};
if (mywords.ContainsKey("apple")) Debug.Log("Apple found!");
if (mywords.ContainsValue("animal")) Debug.Log("Animal found!");
But an ArrayList does allow you to access elements by index (rather than key only) and perform Sort() operations.
I’ve been playing around with ArrayLists as suggested and seem to be on the right track.
I take it that populating the list with .Add on start up is the only way to create the list? I tried using “var testlist = new ArrayList (“a”, “b”, “c”);” like an array, but it returns an error (no visible constructor iirc). I don’t forsee this .Add method being a problem, just want to double-check that I’m not missing something obvious!
I can use .Contains on an ArrayList, but not an Array (this may vary in other languages, I couldn’t say). With an Array I had to loop through entry by entry (which just crashed Unity under the strain).