12-01-2005, 01:01 AM
Hey guys. Long time no see. Anyway, here's the deal:
I'm currently trying my hand at programming a Chatroom simulator (don't ask; I was bored), and I'm having a little trouble with the basics. You see, I'm storing the responses to and from the "characters" within a text file that looks like this:
I obtain these responses by using this code:
If the user types something that isn't in the conversation file, I make the characters say "huh?" However, that is not the problem. I want the characters to respond to someone in a certain way if a certain keyword is within that sentance, i.e. if someone says "hola amigos sup" the other characters would respond with "how yah doin'" or "hello".
The catch: I don't know how to do this.
The code only makes the characters respond as appropriate if the reply is one word and is in the conversation file (the characters respond if the user types "hi", but not if the user types "hi gang what's going on?"). I've tried using FOR-NEXTs within each other, letter counting (letter$ = letter$ + MID$(string$, loop var, 1)), and MID$ itself, but I can't get anything to work.
Can someone guide me in the right direction? :-?
PS: I'm making this in FreeBasic, but it seems to me the code I currently have would look no different than if I wrote it into QBASIC. I also didn't post all the code because I thought that would've been a waste of time.
I'm currently trying my hand at programming a Chatroom simulator (don't ask; I was bored), and I'm having a little trouble with the basics. You see, I'm storing the responses to and from the "characters" within a text file that looks like this:
Quote:@HELLO HI HOWDY SUP HEY
8
hi
hello
sup
how ya doin'
howdy
nice 2 c u
ello
hey dude
@BYE CYA
8
cyah
adios
so long
ttfn
bye
bi
ciao
hasta luego
...etc, etc...
I obtain these responses by using this code:
Code:
Sub GetResponse(user as STRING, response AS STRING)
Open "conversation.txt" For Input As #1
Do While Not EOF(1)
Input #1, doodad$
If LEFT$(doodad$,1) = "@" AND INSTR(doodad$, user$) Then Exit Do
Loop
Input #1, totalrec$
num = Int(Rnd * VAL(totalrec$)) + 1
Do While Not EOF(1)
Input #1, response$
cnt = cnt + 1
If (cnt = num) Then Exit Do
Loop
Close #1
End Sub
If the user types something that isn't in the conversation file, I make the characters say "huh?" However, that is not the problem. I want the characters to respond to someone in a certain way if a certain keyword is within that sentance, i.e. if someone says "hola amigos sup" the other characters would respond with "how yah doin'" or "hello".
The catch: I don't know how to do this.
The code only makes the characters respond as appropriate if the reply is one word and is in the conversation file (the characters respond if the user types "hi", but not if the user types "hi gang what's going on?"). I've tried using FOR-NEXTs within each other, letter counting (letter$ = letter$ + MID$(string$, loop var, 1)), and MID$ itself, but I can't get anything to work.
Can someone guide me in the right direction? :-?
PS: I'm making this in FreeBasic, but it seems to me the code I currently have would look no different than if I wrote it into QBASIC. I also didn't post all the code because I thought that would've been a waste of time.