2D Array containing tiles for world creation

Good evening! Myself and a friend are having a bit of trouble - or rather a lot of trouble trying to produce a script to create a world for us. What we need is to have a script attached to a “World Spawner” object that not only creates tiles in a grid for use in our game, but to make it possible for the tiles to know which other tiles are adjacent to them.

To clarify, our dinosaur wants to move to another tile. He needs to know what the next tile consists of (water, lava, land etc) before he can move onto it, so he needs to ask the tile he’s standing on for information about the next tile. While we could use other techniques (Raycast from the dinosaur, just create tiles and have triggers where we want stuff to happen) we want a system that can be applied to any game where we need tiles that can communicate with each other when asked to. We’ve worked out that we need a multidimensional array to contain the tile gameobjects which should be created when the array element is defined in the image of a prefab. If we have a multidimensional array, we can use the indexes in a way similar to coordinates to identify adjacent tiles. Here is what we have so far;

var mapsize = 9;	// how big the map should be in tiles...
var IndexX = 0;		// index for ArrayX
var IndexZ = 0;		// index for the array elements of ArrayX

var Tile : Transform;	// Tile prefab to be created
var TileTemp : Transform;	

function Start () 
{
	CreateArrays();	// run the CreateArrays function to create our world
}

function CreateArrays ()
{
	var ArrayX = new Array(mapsize);	// Create the X axis array - this array contains the other arrays
	
	for (IndexX; IndexX < mapsize; IndexX++)	// While IndexX is smaller than the map size variable...
	{
		ArrayX[IndexX] = new Array(mapsize);	// define this element of ArrayX as an array that is as big as the map size
		
		for (IndexZ; IndexZ < mapsize; IndexZ++)	
		{
			// instantiate(randomly generated tile) at position (IndexX, 0, IndexZ)
       		var clone : Transform;
        	clone = Instantiate(Tile, Vector3(IndexX, 0, IndexZ), transform.rotation);	// instantiate object "clone"
        	TileTemp = clone;		// have the temp value become equal to the clone
        	ArrayX[IndexX][IndexZ] = TileTemp;	// make the array element equal to the temp value
		}
		
		IndexZ = 0;	// reset indexZ so this can be repeated until the indexX loop finishes
	}
}

There is some code missing, but I’ve commented what we need to happen in each section. The errors we’re getting are;

Assets/Scripts/WorldSpawn.js(18,14): BCE0034: Expressions in statements must only be executed for their side-effects.
Assets/Scripts/WorldSpawn.js(22,22): BCE0034: Expressions in statements must only be executed for their side-effects.

My brain has completely melted after working on this for hours. I might be completely delusional, but I have no idea what is wrong with the code - researching the error I found that this error comes up when a loop or other statement isn’t doing anything, but all these are doing things.

Thanks in advance,

<>FreakFish<><

bump

Your for loop isn’t initialized properly. The for loop has the following syntax:
for (statement 1; statement 2; statement 3)
{
the code block to be executed
}

Statement 1 is executed before the loop (the code block) starts. ← this is where the error is coming from as you can’t IndexX something.

Statement 2 defines the condition for running the loop (the code block).

Statement 3 is executed each time after the loop (the code block) has been executed.

use
“for (IndexX=0; IndexX < mapsize; IndexX++)”

instead of

“for (IndexX; IndexX < mapsize; IndexX++)”

That’s fixed it, thanks!