Game Development Community

One way to get the amount of filled/placed tiles in a tile layer

by Leroy Frederick · in Torque Game Builder · 06/12/2006 (6:44 am) · 1 replies

What command am i looking for to find out how many active/filled tiles there are in a tile layer or do i have make a function for this?

Thanks in advance! ;)

#1
06/12/2006 (10:50 am)
Never mind, i figured out a way, but it requires that you have custom data on the tiles in question (which thank God, mine do ;)

For any1 interested, heres the process/function(s) below:

function TileLayerObjectNum::onLevelLoaded(%this)
{
	CountNumOfActiveTiles(%this);
}

function CountNumOfActiveTiles(%TileLayer)
{
//REM Reset $NumOfActiveTiles to 0 and store Tile types for checking
	$TileType[0]=TileCustomData1; $TileType[1]=TileCustomData2;
	$TileType[2]=TileCustomData3; $TileType[3]=TileCustomData4;
	
//Rem Search through each tile in layer to check its data for count
	for ( %TileXCount = 0 ; %TileXCount <= %TileLayer.getTileCountX() ; %TileXCount++ ) 
	{
		for ( %TileYCount = 0 ; %TileYCount <= %TileLayer.getTileCountY() ; %TileYCount++ )
		{
//Rem Go througth Tile Types and add to Active Tile count if valid/found			
			for ( %CheckTileType = 0 ; %CheckTileType <= 3 ; %CheckTileType++ )
			{
				if (%TileLayer.getTileCustomData(%TileXCount, %TileYCount)$=$TileType[%CheckTileType])
				{
					$NumOfActiveTiles += 1;
				}
			}
		}
	}
//  error("--- DONE: $NumOfActiveTiles=",$NumOfActiveTiles);
}

unrem 'error("--- DONE: $NumOfActiveTiles=",$NumOfActiveTiles);' to see the amount of active tiles in the console

2 more things

1. if any1 knows an easier (custom data not required/less code) way or/and
2. knows how to get the amount of items in an array (e.g. ArrayCount(MyArray[0]);),

...please feel free to share your knowledge and wisdom! ;)