Public Group

# text-ual maps

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

## Recommended Posts

I needed a map system allow two dimensional travel in a text-RPG. but for some reason i can't continue because I'm stuck with this error message
...\maps.cpp(19) : error C2143: syntax error : missing ';' before '.'

here's the second file of my code:
//key
//"0"=water, surfable
//"1"=land, passable
//"A"=obstacle

struct Map{
int Bank;
int ID;
int IDleft;
int IDright;
int IDup;
int IDdown;
int width;
int height;
char szName[20];
char szMAP[100][100];
}YourRoom;

YourRoom.Bank=0; //line 19
YourRoom.ID=0;
YourRoom.IDleft=-1;
YourRoom.IDright=-1;
YourRoom.IDup=-1;
YourRoom.IDdown=-1;
YourRoom.width=9;
YourRoom.height=7;
YourRoom.szMAP[0][]="AAAAAAAAAA";
YourRoom.szMAP[1][]="AAAAAAAA1A";
YourRoom.szMAP[2][]="A11AAAA11A";
YourRoom.szMAP[3][]="A11111111A";
YourRoom.szMAP[4][]="A11111111A";//start pos is 4th spot;
YourRoom.szMAP[5][]="AA111AA11A";
YourRoom.szMAP[6][]="AA1111111A";
YourRoom.szMAP[7][]="AAAAAAAAAA";


I believe the problem lies with how i declared YourRoom, because when i hover my mouse over YourRoom, it pops up a tip saying "int YourRoom" Unfortuanately i don't know how to fix it.

##### Share on other sites
Alright, I tried out your code but I might be 100% wrong because I use structs different then you. I got no errors at all. Sorry if it doesn't work or if I'm 100% off.

struct Map{	int Bank;	int ID;	int IDleft;	int IDright;	int IDup;	int IDdown;	int width;	int height;	char szName[20];	char szMAP[100][100];};// Assuming this is before int main()// Now inside int main()Map YourRoom ={	0,	0,	-1,	-1,	-1,	-1,	9,	7,	"Your Room",	"AAAAAAAAAA",	"AAAAAAAA1A",	"A11AAAA11A",	"A11111111A",	"A11111111A",	"AA111AA11A",	"AA11111A",	"AAAAAAAAAA"};// This follows the same template in the strut.

Now if you want to call anything up use this for example to show the bank amount:

cout << YourRoom.Bank;

Or if you want to change it.

YourRoom.Bank = YourRoom.Bank + 1000;

It will use your template you set above and show 0 on the screen, just like you declared it.
I hope this works for you, if not I'm sorry.

##### Share on other sites
I'm sorry, is this CPP that you used? I'm also using Visual CPP 2008 Express Edition.

That's what I'm using.

btw: What i meant by Bank, is a group of similar maps.

------ Build started: Project: PKMNtext, Configuration: Debug Win32 ------Compiling...maps.cppc:\documents and settings\brenda\my documents\visual studio 2008\projects\pkmntext\maps.cpp(18) : error C2470: 'YourRoom' : looks like a function definition, but there is no parameter list; skipping apparent bodyBuild log was saved at "file://c:\Documents and Settings\Brenda\My Documents\Visual Studio 2008\Projects\PKMNtext\Debug\BuildLog.htm"PKMNtext - 1 error(s), 0 warning(s)========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

That's what i got.

##### Share on other sites
Yes I used C++. I'm using Visual Studio 2008 Professional.

I believe I made a mistake for the multidimensional array though my bad.
I don't believe I declared it right.

Everything else should work though. Other then the multidimensional array the problem could lay in your other code.

I believe it's saying it can pick up YourRoom, but it doesn't read anything from it. Such as YourRoom.Bank

##### Share on other sites
There's two things I see wrong, and fixing them, it looks like it works fine.

One, be sure that you're assigning to YourRoom within a function. It gives exactly the error(s) you mentioned when the assignment statements are outside a function body, probably because you can only create/initialize variables there.

Two, instead of "YourRoom.szName[]="Your Room";", do "strcpy(YourRoom.szName, "Your Room");", and likewise for the others. You can't assign a string literal like that outside of initialization.

Incidentally, I think MrCpaw had it right, too. He's initializing the object instead of assigning the strings to it later on, so I -think- that would work both inside and outside a function's body.

EDIT: Actually, on point two, be careful you don't overrun the bounds of the destination string (szName). strcpy() ignores array bounds (and has no way to check anyways).

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633696
• Total Posts
3013390
×