Skip to main content
GameDev.net gamedev.net
🔒 Locked

Array of Structs

Started by The Heretic Jan 27, 2003 at 8:04 AM 3 replies 300+ views
Original Post
The Heretic
The Heretic
Recently I have been trying to compile a file with this in it:
  
const unsigned short STARTROOM = 1;                                                 //The first room for a new player

const unsigned short TOTROOMS = 10;                                                 //The total number of rooms

const unsigned short TOTCAPS = 10;                                                  //The total number of rooms


//Info strings

const char* mapInfo[TOTCAPS] = {{"You stand in the center of town near a well.\n\n"},
                                 {"This down town is surprisingly clean.\n\n"},
                                 {"So many shops, so little time...\n\n"},
                                 {"This blacksmith is hot, probably because of the huge fire.\n\n"},
                                 {"The item shop. You an .buy plenty of stuff here.\n\n"},
                                 {"A ton of flashing lights and slot machines make up this casino.\n Beware, gambling is a tax on people who are bad at math...\n\n"},
                                 {"Ahh... Mo''s Tavern. Time for a few rounds?\n\n"},
                                 {"All the houses in this neighborhood look exactly the same...\n\n"},
                                 {"The open road...\n\n"},
                                 {"This forest is thick, but there is still see plenty of light coming through the branches.\n\n"}};

//The map

struct room;
const room map[TOTROOMS] = {{0, 0, 0, 0, 0},
                            {2, 8, 0, 7, 0},
                            {0, 1, 3, 6, 1},
                            {5, 0, 4, 3, 2},
                            {0, 0, 0, 3, 3},
                            {0, 3, 0, 0, 4},
                            {0, 0, 2, 0, 5},
                            {0, 9, 1, 0, 6},
                            {1, 10, 0, 9, 7},
                            {7, 10, 8, 0, 8},
                            {8, 0, 0, 0, 9}};

//The room struct

struct room
{
     unsigned short nID;                                                            //Where to go north

     unsigned short sID;                                                            //Where to go south

     unsigned short wID;                                                            //Where to go west

     unsigned short eID;                                                            //Where to go east

     unsigned short info;                                                           //The description of the room

};
  
The compiler tells me that map has an incomplete type then refuses to compile because map is uninitialized... I''m completely stumped as to why it''s doing this. I''m sure I''m initializing the array properly. Anyone have any ideas?
AndyGeers
AndyGeers
Your mapInfo structure is initialised wrongly:

Instead of saying ....... = {{"blahdeblah"}, {"blahblahblah"}} just say ....... = { "Blahdeblah", "blahblahblah" }

i.e. only one set of braces around a list of strings.
Qw3r7yU10p!
Qw3r7yU10p!
struct room needs to be visible before map. The forward declaration you currently have doesn''t provide enough information to properly create the array.

struct room;
const room map[TOTROOMS] = //

you need to put the real definition of struct in place of struct room;
VXG
VXG
Actually the compiler ignores the inner braces, so there''s nothing wrong with = {{"blahdeblah"}, {"blahblahblah"}}.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.