Error accessing arrays in certain circumstances


(BlueZumbrellas) #1

Hi there!

I’m having a spot of trouble with my level select screen. I have a for each function that goes through and grabs each level in a game mode (a multi-dimensional array with the first array being the stage and each array within holding level information):

public function addButtons():void
{
	for each (var a:Array in LevelLists.normalModeLevelList)
	{
				
	}
}

public static var normalModeLevelList:Array = new Array(
		[LevelEmbed.LEVEL_01_01, GFXEmbed.TILEMAP_DEFAULT, 0, true ],
		[LevelEmbed.LEVEL_01_02, GFXEmbed.TILEMAP_DEFAULT, 1, false ],
		[LevelEmbed.LEVEL_01_03, GFXEmbed.TILEMAP_DEFAULT, 2, false ],
		[LevelEmbed.LEVEL_01_04, GFXEmbed.TILEMAP_DEFAULT, 3, false ],
		[LevelEmbed.LEVEL_01_05, GFXEmbed.TILEMAP_DEFAULT, 4, false ]);

I’m testing the game from the first stage. On this, clicking the button to return to the menu works fine, however after completing a level and trying the same crashes the game and returns:

[Fault] exception, information=TypeError: Error #1034: Type Coercion failed: cannot convert true to Array.

The detailed information doesn’t seem to help, only referencing the world downwards as the problem, and a looks to be functioning properly (that I can see):

Any help would be appreaciated as having to re-design my entire level structure would suck. Cheers :slight_smile:


(Abel Toy) #2

Mhmm… how are you marking a level as completed? I’m guessing that’s the last “true / false” stuff, but how are you setting it to true once completed? I’d like to see some code.

Also, seeing a bit of code of how you make the buttons would be interesting. Can’t figure out the problem right now :confused:


(BlueZumbrellas) #3

Found the problem, I forgot to reference the second array (normalModeLevelList[currentLevel] instead of normalModeLevelList[currentLevel][3]) hence why it was only erroring when a level was completed.

The perils of coding at 3am in the morning…


(Alex Larioza) #4

Now add a beer and a few shots. :smiley: