I’m building a scrabble-like word game and loading a text file containing a list of words that is 80000 words in length.
It seems like it is only loading part of the list and not the whole thing. When I try to access a value past 1000 I get an error. Is there a better way to do this
var wordCSV : TextAsset;
var wordArray = wordCSV.text.Split(";");
var wordList = new HashSet.< String >(wordArray);
Debug.Log (wordString + " is a WORD!!");
Debug.Log (wordString + " not in dictionary");
If your dictionary is sorted (and it should be) you shouldn’t be loading the whole thing in to memory. You should access the file and move the file pointer half way in. Check to see if your word comes before or after that point. If before, move the file pointer half way back and check again. If after, move half way after and check again. Keep doing this half and half until your word is found directly in the file. AT MOST - this will require ONLY 16 such searches in a file of 50,000 words to find the right one and will execute blazingly fast with minimal memory footprint.
I use something similar to the following… I haven’t notice any slow down at all and my dictionary is close to 200k words.
var myDictionary : Dictionary.<String, String>;
var wordToCheck : String;
var MytextAsset = Resources.Load("dictionary", typeof(TextAsset)) as TextAsset;
myDictionary = MytextAsset.text.Split("
function checkWord(word : String)
Debug.Log(wordToCheck + " is a valid word");
Debug.Log(wordToCheck + " is NOT a valid word");