GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-May-2009, 23:29
Wuzzin Wuzzin is offline
New Member
 
Join Date: May 2009
Posts: 6
Wuzzin is on a distinguished road

Extracting Keywords from user input


I currently trying to make a text based game, and yes it is for school, while planning out how i was going to code this program I realized that I was going to have to search for any and all variations of what i want the user to do.

take the example of: Take Pillow (this is what i would like the user to type)

the user may type out Take the pillow, or take the pillow off of the table, or many other variations, but all I am interested in is the Take and Pillow.

I'm asking if there is an easier way to define keywords and just search the user's text for these keywords, and if so how i would go about doing so.

Thanks in advance for your time, and if there are any questions about my explanation please ask.

~Wuzzin~
  #2  
Old 08-May-2009, 04:02
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 226
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: Extracting Keywords from user input


Quote:
Originally Posted by Wuzzin
I currently trying to make a text based game, and yes it is for school, while planning out how i was going to code this program I realized that I was going to have to search for any and all variations of what i want the user to do.

take the example of: Take Pillow (this is what i would like the user to type)

the user may type out Take the pillow, or take the pillow off of the table, or many other variations, but all I am interested in is the Take and Pillow.

I'm asking if there is an easier way to define keywords and just search the user's text for these keywords, and if so how i would go about doing so.

Thanks in advance for your time, and if there are any questions about my explanation please ask.

~Wuzzin~


You'll want a container of verbs and another of nouns. Then, for each "location," in your game, you'll want to have a verb:noun relationship defined such that your text processor can make suitable matches or inform the user of any issues it has with processing user input.

If you haven't played Zork, you may want to give it a look.

http://www.csd.uwo.ca/Infocom/


MxB
  #3  
Old 08-May-2009, 21:10
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Extracting Keywords from user input


The original game of this type can be found at http://www.rickadams.org/adventure/e_downloads.html. Even Zork has Adventure as a parent.

Quote:
Originally Posted by Wuzzin
I'm asking if there is an easier way to define keywords and just search the user's text for these keywords, and if so how i would go about doing so.
You didn't tell us how you are defining the keywords nor searching the text. We therefore can't tell you if there's an easier way.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #4  
Old 11-May-2009, 16:00
Wuzzin Wuzzin is offline
New Member
 
Join Date: May 2009
Posts: 6
Wuzzin is on a distinguished road

Re: Extracting Keywords from user input


i'm going to try to extract the data as a string and search the string for certain words by using wildcards such as *take*, now just have to figure out what the wildcard characters are in Visual C++
  #5  
Old 12-May-2009, 20:10
Wuzzin Wuzzin is offline
New Member
 
Join Date: May 2009
Posts: 6
Wuzzin is on a distinguished road

Re: Extracting Keywords from user input


if (txtInput->Text == "take pillow")
(txtInfo->Text +="Pillow taken.");
lblPillow->Visible = true;


if (txtInput->Text == "drop pillow")
(txtInfo->Text +=("Pillow dropped."));
lblPillow->Visible = false;
  #6  
Old 12-May-2009, 20:14
Wuzzin Wuzzin is offline
New Member
 
Join Date: May 2009
Posts: 6
Wuzzin is on a distinguished road

Re: Extracting Keywords from user input


txtInput is my textbox for the user's input
txtInfo is the main window with all the data that the user needs to read
the Labels (lblPillow) is how i will show inventory items by setting them visible
all i am doing is having the program look at the text in the txtInput (much easier than my first plan to pull the text out into strings). i am fine with this setup i am no longer looking to do wildcard searches, but now i'm having trouble getting my labels to go visible and invisible, thanks for your help : )
~Wuzzin~
  #7  
Old 18-May-2009, 18:30
Wuzzin Wuzzin is offline
New Member
 
Join Date: May 2009
Posts: 6
Wuzzin is on a distinguished road

Re: Extracting Keywords from user input


Ok, ive gotten every little glitch in my program worked out, except one.
i am returning the preset responses to the user inputs by using += text to the textboxes such as this:
else if ((txtInput->Text == "north") || (txtInput->Text == "south") || (txtInput->Text == "west")){
(txtInfo->Text +="\r\nYou walk into the wall, and as expected, it doesn't budge.");

these are displaying in a multiline textbox, but the textbox resets to the top so that you have to scroll down after every input.

I am looking for a way to have the program automatically scroll to the bottom of the multiline textbox so you can see what was just displayed.

Thanks again for you help GID,
~Wuzzin~
  #8  
Old 18-May-2009, 21:51
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Extracting Keywords from user input


You really have to think through the input/parse/comparison mechanism much more thoroughly. What happens if the user types
Code:
Take pillow take Pillow take pillow get Pillow keep pillow
All of the above should do the same thing.

The way Adventure handled it, there were many verbs defined, something like
1 take get keep
so each of the words is translated into the number 1. And verb 1 has a specific definition. Then there's a list of objects, also turned into numbers.

So you really need to carefully define how the input works, write that section, and get it working well. Then you simply call it from main() and process the values returned.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #9  
Old 19-May-2009, 13:24
Wuzzin Wuzzin is offline
New Member
 
Join Date: May 2009
Posts: 6
Wuzzin is on a distinguished road

Re: Extracting Keywords from user input


I am just going to have a strict syntax message in the beginning, it is just for our final exam in Computer Programming 2. ive already cleared how my inputs are going. I'm just trying to get my textbox to show the bottom instead of resetting to the top every time new text gets put in it.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Separating a letter and number from user input slyslick C++ Forum 2 25-Feb-2009 01:04
Scanning dilemma (fscanf and fgets) aijazbaig1 C Programming Language 10 29-Mar-2008 05:58
Creating Variables based on user input oddsprite C++ Forum 9 01-Nov-2007 05:31
Need help with validating user input. Emmy C++ Forum 4 19-Aug-2007 12:07
Need Help on checking user input hihellochao C Programming Language 5 27-Feb-2004 14:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:39.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.