index is less than 0 or more than equal to the list count

Have this : Need help to resolve asap - Thanks

Function BuildDeck()
var totalRobots:int = 4;
var card:Object;

for(i=0; i<totalRobots.length; i++)
var aRobotParts:Array = [“Head”, “Arm”, “Leg”];
for(j=0; j<2; j++)
var someNum:int = Random.Range(0, aCards.length);
aGrid*[j] = aCards[someNum];*

  •   	var theMissingPart:String = aRobotParts[someNum];*
  •   	aRobotParts.RemoveAt(someNum);*
  •   	card = new Card("robot" + (i+1) + "Missing" + theMissingPart);*
  •   	aCards.Add(card);*
  •   	card= new Card("robot" + (i+1) + theMissingPart);*
  •   	aCards.Add(card);*

Maybe this because you are removing elements while iterating? Randomly removing elements in an iterative loop may not be the best idea may be able to get it to work? I would tend to build up my list of things first e.g. create your random elements inside the loops then use that list to remove all at once outside

//outside loops before - note using C# syntax and need to include
var removeList = new List();

//inside loops
var someNum:int = Random.Range(0, aCards.length);
aGrid*[j] = aCards[someNum];*
removeList.Add(Random.Range(0, aCards.length));
//outside loops after
removeList.ForEach(removeItem => aCards.RemoveAt(removeItem));
Just a guess - no offence but the codes a bit hard to read :slight_smile:

First, you seem to be missing the end of your function code, so posting the rest of that (and formatting the beginning code) would help.

Second, you are declaring someNum inside your inner loop (the j loop), then using its value after that loop is entirely finished. You’ll probably want to move your other code that is using someNum into the inner loop so it gets run once for each value of someNum. Because right now you are removing two cards (one for j=0 and j=1) then adding two cards after the loop is finished with only the last value of someNum.