OK, I am doing something wrong trying to get a selected item from an array into a variable.
function SelectWord ()
{
// --- create basic word list in an array of words
wordArray = new Array (
["true","word1","definition1"],
["true","word2","definition2"],
["true","word3","definition3"],
["true","word4","definition4"],
["true","word5","definition5"],
["false","word6","thisisnotarealword6"],
["false","word7","thisisnotarealword7"],
["false","word8","thisisnotarealword8"] // no comma at end
);
// --- end basic word list
// check PlayerPrefs recent words list up to 10 times
// to see if word chosen was used within the last 100 plays
var loopCount = 0;
var loopLimit = 10;
var keepLooping = true;
while( keepLooping ) {
// choose random word for gameplay based on wordArray.length
wordIndex = Random.Range(0,wordArray.length);
if( !IndexTooRecent( wordIndex ) || loopLimit == loopCount++) {
keepLooping = false;
}
}
// add boolean, word and definition into static variables to be used in the various gameplay scenes
isItAWord = wordArray[ wordIndex ][0];
wordShown = wordArray[ wordIndex ][1];
wordDefinition = wordArray[ wordIndex ][2];
}
The error, “Type ‘Object’ does not support slicing”, is being called on this line …
isItAWord = wordArray[ wordIndex ][0];
But I assume it would also apply to the following two as well.
The goal is to randomly select from my array of words (testing to see if it was a recently played word) and then push the result (true/false, word, definition) from the array into the three variables. I think it has something to do with how I am trying to grab the one item (i.e., see here … http://boo.codehaus.org/Slicing) but don’t know how to resolve it.
Any help appreciated.
Also, what would I do to put the wordArray code into a completely separate script … in other words, to remove it from this one to allow someone else to compile it and then simply call it into that line like an include?
Again, thanks!