class steps
{
var fScore:int;
var hScore:int;
var gScore:int;
var openClose:boolean;
}
var test:int;
var step:steps[,];
function Start () {
//closedList = new boolean[20, 20];
step = new steps[3, 3];
step[2,2].openClose=true;
}
Including the error message, so we know which line specifically is giving trouble, would have been helpful.
The problem is line 15. You’ve created an array, but not initialized it, and then on line 15, you’re attempting to access an array element that hasn’t been created yet. You either need to initialize your array, or check if array entries are null before attempting to access them.
So is the problem with the way I’m using the class?
Time to go back to basics. I recommend you google up some tutorials on arrays,initializing them, and why they need to be initialized.
Does anyone know why this works but not the former with the array?
class steps
{
var fScore:int;
var hScore:int;
var gScore:int;
var openClose:boolean;
}
var test:int;
var step:steps;
function Start () {
step.openClose=true;
}
It might not like the array being sized in the start function.
Not saying this will work, but you could try:
var step:steps[,] = new steps[3,3];
It has nothing to do with where the array is sized. I stated the problem, and the knowledge needed to fix it.
OK, for a hint, you just need to initialize the class that you are going to add the value right before you add the value, or you could initialize the entire array. I think this is a javascript deal, because I don’t remember having this problem or even thinking about it before. Then again, maybe I just got an error and fixed it.