For loop not repeating - (JAVASCRIPT)

Hello, everyone. I’m working on a memry card game and using the “iphone Game 4.0” code as a base. (it’s a memory card game…)

Whenever I run the code, it doesn’t create the cards because of this error:

ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index

I’ve looked on the forums and cannot find a satisfactory answer - I’ve even copy-and-pasted the code from the old script intO my project file.

Here is the code:

#pragma strict

var cardLocations =	new Array 
( 
	Vector3 (0, 0, 0), Vector3(3, 0, 0), Vector3(6, 0, 0), Vector3(9, 0, 0), Vector3(12, 0, 0), Vector3(15, 0, 0),
	Vector3 (0, 0, -4), Vector3(3, 0, -4), Vector3(6, 0, -4), Vector3(9, 0, -4), Vector3(12, 0, -4), Vector3(15, 0, -4),
	Vector3 (0, 0, -8), Vector3(3, 0, -8), Vector3(6, 0, -8), Vector3(9, 0, -8), Vector3(12, 0, -8), Vector3(15, 0, -8)
);

var allCards : GameObject;
var parentObject : GameObject;

var usedCardLocation;

var uniqueCard = new Array ();


function Start () { 
{	
	// Find all Game Objects that are Tagged "Cards"...
	
	uniqueCard = allCards.FindGameObjectsWithTag ("Cards");
	
	// Randomize the order of the Cards...
	
	for ( var c=0; c <= uniqueCard.length-1; c++)
	{
		var thisCard = Random.Range (c, uniqueCard.length);
	
		usedCardLocation = uniqueCard 
;
    		
    		uniqueCard [c] = uniqueCard [thisCard];
    		
    		uniqueCard [thisCard] = usedCardLocation;
    	}
    	
    	// Randomize the order of the Card Locations...
    	
    	for ( var i=0; i <= cardLocations.length-1; i++)
    	{
    		var thisCardLocation = Random.Range (i, cardLocations.length);
    		
    		usedCardLocation = cardLocations *;
    		
    		cardLocations * = cardLocations [thisCardLocation];
    		
    		cardLocations [thisCardLocation] = usedCardLocation;
    		
    		// Instantiate our Randomized Cards and parent them to empty Game Objects so the animations play in Local Space...
    		
    		var theCard : GameObject = Instantiate (uniqueCard [i/2], Vector3(0,0,0), Quaternion.identity);
    			
    		var theParent : GameObject = Instantiate (parentObject, Vector3(0,0,0) , Quaternion.identity);
    		
    		theCard.transform.parent = theParent.transform;
    
    		
    		theParent.transform.position = cardLocations *;
    	}
    	
    	// Destroy the group of cards that we're using to generate the Card Locations...
    Destroy(allCards, 0.1);
    
    
    }
    }

Can somebody please help me?

Thanks!

-Sam

I created a scene with a parent object, and 3 cubes tagged with “Cards” and dropped your code in and it stopped with “parentObject is unassigned”.

If I removed the Cards tags, I get the error ArgumentOutOfRangeException like you do. So perhaps you don’t have the tags setup correctly?
[25016-cardshuffle.zip|25016]