movement system for text based game

array of structures problem

Page 1 of 1

1 Replies - 5295 Views - Last Post: 10 January 2009 - 12:43 AM Rate Topic: -----

#1 badjava   User is offline

  • Lux Ex Tenebris
  • member icon

Reputation: 14
  • View blog
  • Posts: 540
  • Joined: 30-October 08

movement system for text based game

Post icon  Posted 10 January 2009 - 12:34 AM

I am getting to the stage of trying out some code ideas for my text based adventure game, only 5 rooms right now keeping it super simple. Again this is just to test the movement portion.

We have a thread going in the game development forum here, but I'm at the stage of C++ specific questions and thought I should post in here to get some assistance.

It looks like I can't get away with using this #define variable in the array of structures creation statement. I get errors that what ever is between the [ and ] is basically not legal. I can understand it since it doesn't have a type so how do you work around this? This is probably something really simple that I'm not thinking of...
#include <cstdlib>
#include <iostream>

using namespace std;

#define max_locations 5;
#define max_directions 4;

typedef struct t_rooms {
   int id_number;
   char *roomname;
};

typedef struct t_locationinfo
{
   int location_id;
   char *description;
[b]   t_rooms room_array[max_directions];[/b]//errors here
//tried this also using a created/named instance of the first struct rather
//than it's type and that generated MANY more compile errors than this one
};

int main(int argc, char *argv[])
{
    system("PAUSE");
    return EXIT_SUCCESS;
}


Line 18: t_rooms room_array[max_directions];
gives these errors: "expected `]' before ';' token" and "expected unqualified-id before ']' token".

I have also tried to create this array using a named instance of the defined structure type and that generated a lot more errors than my current version of broken code.

What do you guys see wrong with my structure array?

Is This A Good Question/Topic? 0
  • +

Replies To: movement system for text based game

#2 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: movement system for text based game

Posted 10 January 2009 - 12:43 AM

Working example:
#include <cstdlib>
#include <iostream>

using namespace std;

#define max_locations 5
#define max_directions 4

struct t_rooms {
   int id_number;
   char *roomname;
};

struct t_locationinfo {
   int location_id;
   char *description;
   t_rooms room_array[max_locations];
};

int main() {

	cin.get();
	return 0;
}


List of errors:
- typedef is unneeded
- the #define had a semicolon, thus making "max_directions" not "5," but "5;" which is an array as an array-element

Other than that, it's fine.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1