Advertisement

HELP!!!!!!!!!! I need help making a conversation generator

Started by January 03, 2000 06:56 PM
5 comments, last by Stoopid_Old_Me 24 years, 11 months ago
I need help making a conversation generator! I am making a game as close to AD&D as possible!!! But it will be part text and very little graphics. But I need to be able to have my players ask a question and it will generate an answer. I kinda don''t want the same answer all the time like final fantasy when you talk to someone twice! If you can help please reply!!!!!!
You could use a loop and a function. The function would be called when the player asks the question.

int Respond_to_Question(void)
{
int a;

for(a=0;a<2;a++)
{
if(a==0)
{
//respond with message #1
}
if(a==1)
{
//respond with message #2
}
ect.
Visit http://members.xoom.com/ivanickgames
Advertisement
Correct me if im wrong C++ Freak (I often am :) but wouldn''t what you suggest simply display two responses every time you talk to them?

I suggest a static variable which you increment each time

e.g.

int Respond_To_Question(void)
{
static int a;

// Just a little chck to make sure we don''t go above your amount of responses (assumes MAX_RESPONSES is a define for your amount of responses)
if(a<MAX_RESPONSES)
a++;

switch(a)
{
case 0:
{
// respond with msg #1
break;
}
case 1:
{
// respond with msg #2
break;
}

etc
Well the way my could currently is, it one display message one the first time you asked them,and message 2 the second time you ask them. My code did have one error, after you asked them twice it wouldn''t display a message. Your code would work too. A better version of my code would be:

int Respond_to_Question(void)
{
int a;

for(a=0;a<3;a++)
{
if(a==0)
{
//respond with message #1
}
if(a==1)
{
//respond with message #2
}
if(a==2)
{
//respond with message #3
}
if(a==3)
{
a=0;
}
}

You could easily add more responses by changing the for statement. to make it have 12 responses you would just have to change

for(a=0;a<3;a++)

to

for(a=0;a<12;a++)

and than add more if statements so then you could have 12 responses.

I''m not familair with the method you used but I think your way would work. I could give you a full working dos source if you wanted me too.
Visit http://members.xoom.com/ivanickgames
I can''t see how your code would work
Ill run through it here...

You get into the for loop
To put it in English, we will loop 2 times
First time a==0
Second time a==1

So your code checks *inside* the for loop whether a is 0 or 1

If you see what I mean during the loop stage it will be both 0 *AND* 1 therefore both responses will be output.

If you try and remedy this with a return in the a==0 case you will never get to see the second response.

I think the only way around it is to have a static variable (if your not sure what this is, its a variable that keeps its last value even after it has passed out of scope)

Anyway - all of this is a moot point, as after re-reading Stopid_Old_Me''s question again I realise he actually wants to know how to make some kind of interpreter, not just fixed responses.
I need more of a class that would store multiable responses!!!

example::
Player:Where is Grakhirt''s Lair!
Computer:Grakhirt''s Lair is North for 3 day! Stay on
trail or ~~~~

I need it to parse the first sentance and respond under certian conditions and the player;s stats!
Advertisement
This would be extremely difficult to achieve without a lot of this:

Player: Where am I?
Computer: I don''t understand that.
Player: Where is Player?
Computer: Could you rephrase the question?
Player: What is this place?
Computer: Well, this is sherwood forest!

What i''m getting at is that every player phrases questions differently, and you have to cover all of them.

My advice is, that whatever you do, DO NOT just compare whole strings (eg strcmp(Input, "Where am I?")) because there are too many responses.

Your best bet is to parse the sentence, getting a word at a time and checking for relevant information. e.g.

Take the phrase ''Where am I?''
While being parsed you could do this:

''Where'' means its a locational based statement/question
''am'' can for the most part be ignored
''I'' means its got something to do with the player
''?'' its a question

So you now know its a question about where the player is.

And the great thing is most of the code would work again, ie if you then run ''Where is player?'' it would do exactly the same thing. And you only have to cover keywords.

I would envisage this type of system arranged like a tree, with each branch getting closer to the real meaning of the statement.

Wow, Im really ranting here - anyway - good luck with it, I certainly wouldn''t like to attempt such a system in a hurry, although once completed it would be very impressive.

One last thing: try keeping the database of words or whatever in a datafile, then you will be able to expand it much easier, and perhaps even provide a learning ability.

Good luck!

This topic is closed to new replies.

Advertisement