Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Help with MUD

I want to make a simple MUD in C++ the first thing im trying to do is make a walking system and make it so when your in a diffirent room and type "l" it will show you the description of that room; I was thinking I could do this by every time someone moved north it would add 1 to the room integer and when someone typed "l" it would check which number it is and return the description.
However upon doing this I quickly found myself lost, and I have been experimenting the all sorts of different coding methods. This is my current prototype.

#include <iostream>
#include <fstream>
using namespace std;

void look(char l);

int main()

{float name;
int HP, XP, room;
HP = 100;
XP = 0;
room = 1;
void look(char l);
if (room ==1) {cout<<"You are in a grassy plain";} else {cout<<"Fatal error\n";}

cout<<"Whats your name?";
cin>> name;
cout<<"Welcome "<< name <<" \n";

return 0; }

Instead of it saying "You are in a grassy plain" when they type "l" ir does it as soon as the program is ran.

Someone please help me
[1178 byte] By [theillbehaviore] at [2007-11-11 10:24:22]
# 1 Re: Help with MUD
it looks like your trying to put a function body inside main, which isnt allowed.
of course it does the print as you asked it to. you said print the grassy before you did anything else. The program will do what you said in the order you call it, if you want the name stuff first, put it first in main.
jonnin at 2007-11-11 20:59:00 >
# 2 Re: Help with MUD
To track all the rooms, the approach you used will work fine for a simple system. A graph is probably best if the users can modify the "world" or if you want multiple exits from each zone to other zones.
jonnin at 2007-11-11 20:59:54 >
# 3 Re: Help with MUD
it looks like your trying to put a function body inside main, which isnt allowed.
of course it does the print as you asked it to. you said print the grassy before you did anything else. The program will do what you said in the order you call it, if you want the name stuff first, put it first in main.

Whenever I try to put the code for it outside I get the error message error C2447: missing function header (old-style formal list?)
Error executing cl.exe."

What am I doing incorrectly?
theillbehaviore at 2007-11-11 21:00:59 >
# 4 Re: Help with MUD
void foo(); // function header, really belongs in a .h file

void foo() // function body
{
... normal code
}

int main()
{
... code
foo(); // call your function
... more code.
}

what you are doing wrong is syntax. you wouldnt call the funciton in main with a
void foo(); // wrong, and confuses the compiler
you leave the void off here as above.
jonnin at 2007-11-11 21:01:59 >