- Home /
Multi-Dimensional array out of range issues.
Hi. I'm working on something for a class that is a script for a virtual card game. I'm trying to make a multi-dimensional array that will pass a value to the two cards being drawn and remove them from the arrays so that they aren't drawn as duplicates. When I run the script it gives me an out of range exception that conflicts with the script my teacher wrote as the main engine. Here is my code:
class CardArraySetup {
private static var instance : CardArraySetup = new CardArraySetup();
public static function GetInstance() : CardArraySetup
{
return instance;
}
private var totalCardCount = new Array();
private var multiDimensionGrid = new Array();
private var flippedCards = new ArrayList();
function GetCardArray() : Array
{
return totalCardCount;
}
function GetGridArray() : Array
{
return multiDimensionGrid;
}
function GetCardsFlippedArray() : ArrayList
{
return flippedCards;
}
function ResetCardsFlipped()
{
flippedCards = new ArrayList();
}
function GridSetup()
{
for (i = 0; i < rows; i++)
{
multiDimensionGrid[i] = new Array();
for (j = 0; j < column; j++)
{
var someNum : int = Random.Range(0, totalCardCount.length);
multiDimensionGrid[i][j]=totalCardCount;
totalCardCount.RemoveAt(i);
totalCardCount.RemoveAt(j);
}
}
}
}
Why are you using all of these Arrays and ArrayLists? Is your $$anonymous$$cher forcing you to? It makes sense in web JS but it's obsolete for mono development.
Other then the flipped cards array, why are they obsolete? I know you could do it a different way, but I wouldn't be able to say if that'd be more practical.
To answer Jessy, yes I am being forced through it this way to $$anonymous$$ch how multi-dimensional arrays and arraylists work together in JS. I have a background in VBS and use arrays frequently at work in the IT field to push updates and modify settings and whatnot. The reason I'm so beside myself with this is the restrictive nature of the situation. I'm modifying a code, I guess piggyback style, to interface with his engine his way. It's a real bummer. As far as efficiency, I don't feel like getting into the relevance argument or debating whether lists work better than arrays or yatta yatta.
Answer by Ewok · May 11, 2011 at 09:00 PM
So I've fixed everything but one issue. He says that my problem is my multi-dim array should be a sub-index of my totalCardCount that uses someNum to access that sub-index. This is where he lost me. So I at least know that the problem is specifically the multiDimensionGrid[i][j]=someNum; line because that is not what he's asking. Any and all help is appreciated. Random ego-boosting debate can please be directed to non-answer oriented forums. Thanks.
Your answer
Follow this Question
Related Questions
Ai that applies damage when in range? 1 Answer
Unity Enemy Range detection 3 Answers
IndexOutOfRangeException 1 Answer
Shotgun range? 0 Answers
Detect If Object Is Within Range Of Player To Change Object Opacity 1 Answer