Original Post
I am working on my text parser right now. I don't want to post a lot of code, so here is the gist of it.
I separate the string of input into tokens and call three functions to examine them to determine which word is what type and in what position. My parser only takes two words so you're guaranteed either one or two words.
a return of 0 = no word match
a return of 1 = match in word 1
a return of 2 = match in word 2
what is the best or easiest way to determine what the hell the two-word sentence means and what actions the game takes?
Thanks
edit: here is the code I use after the previous code bit, which I think is sloppy and not very professional:
Edited by - randomDecay on January 6, 2002 1:42:25 AM
int verbLoc = 0; int objLoc = 0; int motLoc = 0; // analyze each word to find out what kind of word it is // and which word contains what type verbLoc = Verb(); objLoc = ObjectWord(); motLoc = MotionWord(); |
if ( m_nWords == 1 )
{
if ( verbLoc == 1 )
{
// need object, but check for save, inventory, etc..
}
else if ( objLoc == 1 )
{
// need verb
}
else if ( motLoc == 1 )
{
m_doTravel = true;
}
else
{
// doesn't make sense
}
}
// process these possibilities of two word input
else if ( m_nWords == 2 )
{
if ( verbLoc == 1 && objLoc == 2 )
{
m_doAction = true;
}
else if ( m_vIdent == GO && motLoc == 2 )
{
m_doTravel = true;
}
else
{
cout << "What?" << endl;
}
}
|