• 15
• 15
• 11
• 9
• 10

# Tile based array

This topic is 2817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've been trying to make a tile based array for my game for a while now XD. Tried a lot of things, but still don't get exactly how to do it. So I've decided to ask for some help. I have most of the code(don't know if it will work or not), but I only have one error and that must mean I'm close unless the code I wrote doesn't do anything. So if you can help me fix my error or tell me what I'm doing that is making it occur then I would greatly appreciate it. Thanks in advance.

Anyway here is the error I'm getting:
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\test\test\main.cpp(30) : error C2059: syntax error : ']'

And this is the code(Also this isn't the code in my game it's just the tile fuction and all that to test it out.):

#include "DarkGDK.h"void mapsetup();const int height = 3;const int width = 3;int x;int y;int n;int test[height][width]={	0,0,0,	0,1,0,	2,0,3,};void DarkGDK ( void ){    dbSetDisplayMode (1024,768,32);	dbSyncOn   ( );	dbSyncRate ( 60 );	dbMaximizeWindow ();	dbSetImageColorKey (255,0,255);	while ( LoopGDK ( ) )	{		mapsetup(test[]);		dbSync ( );	}	return;}void mapsetup(int map[][height][width]){	//tiles	dbLoadImage("brickground.bmp",21);	dbLoadImage("sky.bmp",22);	dbLoadImage("red.bmp",23);	for(y = 0, n = 31; y &lt; height; ++y)	{		for(x = 0; x &lt; width; ++x, ++n)		{			if (test[y][x] !=0)			{				if (test[y][x] = 1)				{					dbSprite (21,x*32,y*32,n);				}				if (test[y][x] = 2)				{					dbSprite (22,x*32,y*32,n);				}				if (test[y][x] = 3)				{					dbSprite (23,x*32,y*32,n);				}			}		}	}}

[Edited by - Zahlman on July 7, 2010 6:49:47 PM]

##### Share on other sites
On this line:

mapsetup(test[]);

if you're trying to pass the 'test' array as an argument, you need to omit the brackets:

mapsetup(test);

However, this still won't work because at the top of the file, you have this declaration:

void mapsetup();

which says that mapsetup() doesn't take any arguments. You need to change it to:

void mapsetup(int map[height][width]);

Also, in the definition of mapsetup() below, you have an extra pair of brackets after 'map':

void mapsetup(int map[][height][width])

You need to remove those as well.

BTW, please use source tags when posting long code listings.

##### Share on other sites
When you pass test to map set up, you dont need the brackets unless you were to send a specific position in the map (i.e setUpMap(test[0][1]);, but thats only if you want to send a specific location, if you are sending the entire map, just pass test. Also your parameters are all messed up. I believe it is:

setUpMap(int map[height][width])
{

}

hope this helps.

##### Share on other sites
Thank you so much it ran without any errors, but it didn't do anything when I ran it... So now I got to work on the function itself XD.

##### Share on other sites
You should be checking if test[x][y] == 2. You need two equal signs for comparisons.