Prolog check if

Posted by NickLee on Stack Overflow See other posts from Stack Overflow or by NickLee
Published on 2013-11-06T21:49:47Z Indexed on 2013/11/06 21:52 UTC
Read the original article Hit count: 255

Filed under:
|
|

I'm creating a text adventure game on SWI-Prolog and I want to include (some kind of) dialogs.

What I have so far is:

dialog1(1):- nl,write('blah blah'),nl
             write('a: this is answer a'),nl,
             write('b: this is answer b'),nl.

a:- write('respond to answer a'),nl.
b:- write('respond to answer b'),nl. 

That's pretty much the first dialog. Now I want to create a second dialog similar to the first one.

dialog1(2):- nl,write('blah blah'),nl,
             write('a: this is answer a'),nl,
             write('b: this is answer b'),nl.

a:- write('respond to answer a'),nl.
b:- write('respond to answer b'),nl. 

How can I check if the dialog is the first or the second one? I want to do that because when the user types a., I need the right answer a to be shown.

I thought I could use something like

a(1):- write('respond to answer a'),nl.
b(1):- write('respond to answer b'),nl. 

/* and on the second dialog*/
a(2):- write('respond to answer a'),nl.
b(2):- write('respond to answer b'),nl. 

But still, if the user is on dialog 2 and he types a(1),the first answer will appear.

© Stack Overflow or respective owner

Related posts about if-statement

Related posts about prolog