Hey I am a bit confused about how to properly check a Jagged array for "index out of range exceptions"
Im quite sure im somehow supposed to use the .Length of the array but it confuses me to read this, because my tiles are of a TileType type (enum):
https://msdn.microsoft.com/en-us/library/system.array.length.aspx
What im doing is creating a grid of tiles and running through them after the fact and setting their values to have a collider (red in this case) if they are in the correct position. In order to do this I have to check the tiles surrounding the one I am currently on. This sometimes, albeit rarely, leads to an index of out range exception because the tile I am on is on the edge of the tile grid and thus it cannot find the tile I am looking for.
Here is a small peice of the code:
void SetTilesValuesForRooms()
{
// Go through all the rooms...
for (int i = 0; i < rooms.Length; i++)
{
Room currentRoom = rooms[i];
// ... and for each room go through it's width.
for (int j = 0; j < currentRoom.roomWidth; j++)
{
int xCoord = currentRoom.xPos + j;
//// For each horizontal tile, go up vertically through the room's height.
for (int k = 0; k < currentRoom.roomHeight; k++)
{
int yCoord = currentRoom.yPos + k;
// Make the left wall have colliders
// this line is the culprit
if (xCoord == currentRoom.xPos && tiles[xCoord - 1][yCoord - 1] == TileType.Wall || tiles[xCoord - 1][yCoord] == TileType.Wall)
{
tiles[xCoord - 1][yCoord - 1] = TileType.Red;
if (yCoord == currentRoom.yPos + currentRoom.roomHeight - 1 && tiles[xCoord - 1][yCoord] == TileType.Wall)
{
tiles[xCoord - 1][yCoord] = TileType.Red;
if (tiles[xCoord - 1][yCoord + 1] == TileType.Wall)
{
tiles[xCoord - 1][yCoord + 1] = TileType.Red;
}
}
}
Im quite interested to know how I would properly go about checking if the tile I am about to correct is out of range or not.
thank you.