[C++] Multi Say System (Console)
Posted: Mon Jul 02, 2012 1:30 pm
Hello guys, im making a little project on my own just for fun and i would like to ask you guys if you know how to make a system or a function that can detect multiple commands at once.
I shall make an example:
My project is on command line, and its checking for commands all the time, and i got commands like: Display.All.Ages, and it display ages of a class called bots. But i would like to make like: Display.Ages.1 and it only display the age of the Bot number 1.
Here's how im detecting commands:
First i store them into chars
Then in the update i got:
If you dont know, strcmp will compare the Command to the prebuilt commands and check if they are the same, if yes it returns 0, and the function above is called.
I dont know how to this.. If you guys know tell me please
I shall make an example:
My project is on command line, and its checking for commands all the time, and i got commands like: Display.All.Ages, and it display ages of a class called bots. But i would like to make like: Display.Ages.1 and it only display the age of the Bot number 1.
Here's how im detecting commands:
First i store them into chars
Code: Select all
///Commands
char Command_Hello[256] = "hello";
char Command_Stop[256] = "stop";
char Command_Clear[256] = "cls";
char Command_ShowAge[256] = "display.ages";
char Command_ShowGender[256] = "display.genders";
Code: Select all
cin >> Command; //check for command
if(strcmp(Command, Command_Hello) == 0)
{
cout << "Hello to you sir" << endl;
Blank();
}
else if(strcmp(Command, Command_Stop) == 0)
{
cout << "Bye Bye" << endl;
Blank();
Running = false;
}
else if(strcmp(Command, Command_Clear) == 0)
{
system("cls");
Blank();
}
else if(strcmp(Command, Command_ShowAge) == 0)
{
for(int i = 0; i < 30; i ++)
{
cout << "Bot #" << i << " Age: " << bot.age[i] << " years" << endl;
}
Blank();
}
else if(strcmp(Command, Command_ShowGender) == 0)
{
for(int i = 0; i < 31; i ++)
{
if(bot.gender[i] == 0) cout << "Bot #" << i << " Gender: Female" << endl;
if(bot.gender[i] == 1) cout << "Bot #" << i << " Gender: Male" << endl;
}
Blank();
}
I dont know how to this.. If you guys know tell me please
