#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    7

    Problem with repeat words from array


    Hi, I'm making a small wordpuzzle game, and I have trouble figuring out how to make the game discard the words it has already given to the player.

    I load in the array from an external txt file, and it works just fine. However, it is chosen at random from the list, which means that words get repeated sometimes.

    So I'm looking for help on how to make the words that has already been used unselectable.
    Code:
    function wordsLoaded(event:Event):void
    {
    	var wordString:String = wordLoader.data;
    	var wordArray:Array = wordString.split('\r\n');
    	
    	lineNumber = pickRandomLine(wordArray);
    	
    	var oldString:String = wordArray[lineNumber];
    	
    	word = oldString;
    	wordScore = word.length;
    	
    	var newString:String = randomizeWord(oldString);
    
    		while(oldString == newString)
    		{
    			newString = randomizeWord(oldString);
    		}
    
    	jumble_txt.text = String(newString);
    }
    
    function pickRandomLine(lenght:Array):Number
    {
    	var linePick:Number = Math.round((lenght.length -1) * Math.random());
    	
    	return linePick;
    }
    Any help and/or ideas are much appreciated.
    Last edited by stillwell; November 3rd, 2012 at 08:41 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    7
    I figure that arrays is the way to go, but I just can't figure out how to do the check.

    I added this array, which holds all the line numbers that needs to be excluded.
    Code:
    function pickRandomLine(lenght:Array):Number
    {
    	var linePick:Number = Math.round((lenght.length -1) * Math.random());
    	
    	//Save lineNumber for exclusion from word list
    	exclusionArray[exclusionArray.length] = linePick;
    	
    	return linePick;
    }
    Any help is much appreciated.

IMN logo majestic logo threadwatch logo seochat tools logo