I have been playing around with this method you guys tought me to allocate big arrays. Now that I started to feel comfortable using it I decided to make my life more complicated using it with structs. But it seems there is something about how this works that I have not quite understood yet.
What I am trying to do is use a struct (TILE) that will store the data for each tile in my map. And then place an array of the structs inside (ZONE) that contains the map's tile data (array) along with other usefull data.
This is the small test script I am running before actually implementing it in a game:
#include <acknex.h>
#include <default.c>
typedef struct TILE
{
char highID;//2B
var highDATA;//4B
char highSTATUS;//2B
char highANG;//2B
char lowID;//2B
var lowDATA;//4B
char lowSTATUS;//2B
char lowANG;//2B
ENTITY* highENT;//4B
ENTITY* lowENT;//4B
}TILE;//28B
typedef struct ZONE
{
TILE** TILES;//112MB (2048x2048grid)
int day;//4B
char type;//2B
char mode;//2B
var info;//4B
char spawntype;//2B
int maxspawn;//4B
char spawnrate;//2B
}ZONE;
ZONE MAP;
void map_init()
{
int ty;
MAP.TILES = (TILE**)sys_malloc( (int)2048 * sizeof(TILE*) );
for (ty=0;ty<2048;ty++)
{
MAP.TILES[ty] = (TILE*)sys_malloc( (int)2048 * sizeof(TILE) );
}
}
void main()
{
level_load(NULL);
map_init();
sys_exit(NULL);
}
when running this script it throws the following error at line 40...
Error in 'line 40:
subscript requires array or pointer type
<MAP.TILES[ty] = (TILE*)sys_malloc( (int)2048 * sizeof(TILE) );>
Error E355: Startup failure
Can anyone spot what I am doing wrong?