I used a different approach...
'Response to a knock knock joke
PrevUserSenta = Mid(PrevUserSent, 2, 100)
If Instr (1, UserSentence, "Knock knock", VbTextCompare) > 0 Then
GetResponse = "Who is there?"
JokeA = True 'To track when the joke is on or over.
UserBrainRel = 50 'This makes this response the 'best' reply - in case Hal can come up with a better response.
End If
If Instr (1, PrevSent, "Who is there", VbTextCompare) > 0 Then
GetResponse = UserSentence & " " & "who?"
UserBrainRel = 50
End If
If Instr (1, PrevSent, " who", VbTextCompare) > 0 And Instr (1, PrevSent, PrevUserSenta, VbTextCompare) > 0 Then
Knock = (Rnd * 100)
If Knock < 25 Then
GetResponse = "HAHAHAHAaaaa that's a good one!" & vbCrLf
JokeA = False 'The joke is now over.
End If
If Knock > 24 And Knock < 50 Then
GetResponse = "Ha Ha very funny." & vbCrLf
JokeA = False
End If
If Knock > 49 And Knock < 75 Then
GetResponse = "That was quite amusing." & vbCrLf
JokeA = False
End If
If Knock > 74 And Knock < 101 Then
GetResponse = "That was bad, I wouldn't quit your day job!" & vbCrLf
JokeA = False
End If
JokeB = True 'Now it's Hal's turn to tell a joke.
GetResponseB = GetResponse
End If
JokeA and JokeB varibles, I used later in the script to keep Hal on 'topic' ...
'PROCESS: BLOCK LEARNING IF HAL'S NAME IS DETECTED
'Here we check to see if the user is calling Hal by name; if the user is doing so,
'it's better not to save the sentence for re-use, since it usually makes the
'pronoun-reversed sentence sound clumsy or incorrect:
BlockSave = False
If InStr(1, UserSentence, ComputerName, vbTextCompare) > 0 Then BlockSave = True
If InStr(1, OriginalSentence, ComputerName, vbTextCompare) > 0 Then BlockSave = True
'I added these cause I didn't want Hal to learn these from other bots either.
If InStr(UserSentence, "zabaware") > 0 Then BlockSave = True
If InStr(UserSentence, "ZABAWARE") > 0 Then BlockSave = True
If InStr(UserSentence, "wwwzabawarecom") > 0 Then BlockSave = True
If InStr(UserSentence, "WWWZABAWARECOM") > 0 Then BlockSave = True
If InStr(UserSentence, "
www.zabaware.com") > 0 Then BlockSave = True
If InStr(UserSentence, "
WWW.ZABAWARE.COM") > 0 Then BlockSave = True
If JokeA = True or JokeB = True Then BlockSave = True
'PROCESS: FOCUS ON TOPIC
'See if the user uses a keyword defined in Hal's TopicFocus file. If so Hal will
'set the TopicFocus variable to talk about that topic
If JokeB = True Then
JokeB = False
TopicFocus = 75
**********
You have to create a Focus75.brn and write some jokes in it. For example :
@Why don't blondes have elevator jobs? <yes>You've heard this one...</yes><no>They don't know the route.</no>
A JOKE
@What did the blonde say when she knocked over the priceless Ming vase? <yes>You've heard this one...</yes><no>It's OK Daddy, I'm not hurt.</no>
A JOKE
@Send someone over quickly! the old woman screamed into the phone. Two naked bikers are climbing up toward my bedroom window! This is the Fire Department, lady, the voice replied. I'll have to transfer you to the Police Department. No, it's YOU I want! she yelled. They need a longer ladder!
A JOKE
@What does a blonde think an innuendo is? <yes>You've heard this one...</yes><no>An Italian suppository.</no>
A JOKE
***********
UserSentence = "TELL ME A JOKE"
End If
'RESPOND: PROCESS TOPICFOCUS FILES
'If Hal is currently focusing on a topic, this will read from the appropriate focus file
'First it tries from a topic file specific to the current user, and if that doesn't
'produce results it tries a global topic file that is the same for all users
If TopicFocus > 10 And JokeA = False Then
FocusString = CStr(TopicFocus)
FocusFileNum = Left(FocusString, Len(FocusString) - 1) & "5"
If CInt(Right(FocusString, 1)) > 0 And CInt(Right(FocusString, 1)) < 28 And UserBrainRel = 0 Then
HalUserBrain = HalBrain.QABrain(LongUserSent, WorkingDir & "focus" & FocusFileNum & ".brn", UserBrainRel)
If UserBrainRel > 0 Then
UserBrainRel = UserBrainRel + 50
GetResponse = GetResponse & vbCrLf & HalUserBrain & vbCrLf
If GetResponseB <> "nothing" then
GetResponse = GetResponseB & vbCrLf & HalUserBrain & vbCrLf
End If
End If
End If
End If
'If user didn't follow the subject or change the subject then let's try to get back on track
If TopicFocus < 10 And TopicFocusold > 10 And JokeA = False Then
FocusString = CStr(TopicFocusOld)
FocusFileNum = Left(FocusString, Len(FocusString) - 1) & "5"
If CInt(Right(FocusString, 1)) > 0 And CInt(Right(FocusString, 1)) < 28 And UserBrainRel = 0 Then
HalUserBrain = HalBrain.QABrain(LongUserSent, WorkingDir & "focus" & FocusFileNum & ".brn", UserBrainRel)
If UserBrainRel > 0 Then
UserBrainRel = UserBrainRel + 50
GetResponse = GetResponse & HalUserBrain & vbCrLf
DebugInfo = DebugInfo & " 8 Processing topicfocus files " & TopicFocusOld & " A response of relevance " & UserBrainRel & " was found in the current user topic focus file and this response has been used." & GetResponse & ":" & vbCrLf
End If
End If
End If
I hope this isn't too long... but a number of things were 'fixed' ... first, if there really is a topic, I tried to keep Hal on topic by making 'UserBrainRel + 50' it more important for Hal to stay on topic...
Now I'm thinking how to get Hal to tell a knock knock joke - maybe when he doesn't have any responses, and instead of using the small talk routine...
