the BAS file:
Code: Select all
Screen 19
Type ArraySet
ReDim Keywords(any) As String
ReDim Replys(Any) As String
End Type
ReDim Shared g_Key_Reply(Any) As ArraySet
Dim Shared As string inpt, rply
'Dim user As String = "ronen"
'DIM SHARED TTSvoice as STRING
'TTSvoice = "Microsoft Zira Desktop" 'tts female or male voice (or Zira or David)
RANDOMIZE TIMER
SUB sAppend(arr() AS string, item AS STRING)
REDIM PRESERVE arr(LBOUND(arr) TO UBOUND(arr) +1)
arr(UBOUND(arr)) = item
END SUB
SUB loadArrays(filename AS STRING)
DIM h AS INTEGER = FREEFILE()
DIM fline AS STRING
OPEN filename FOR INPUT AS #h
Dim As Integer IsKeyWord=0,iKeyReplyNum=-1
WHILE NOT EOF(h)
LINE INPUT #h, fline
Var iPosi = InStr(fline,":")
'ignore the line if theres no : or if its too short or too long
If iPosi < 2 Or iPosi > 8 Then Continue While
Var sText = TRIM(MID(fline, iPosi+1))
If iPosi = 2 Then 'check for 1 chracter entries
Select Case fline[0]
Case Asc("k") 'Keywords
If IsKeyWord=0 Then
'if the previous entry was not a keyword add a new set entry
IsKeyWord=1:iKeyReplyNum += 1
ReDim Preserve g_Key_Reply(iKeyReplyNum)
EndIf
sAppend( g_Key_Reply(iKeyReplyNum).Keywords(), sText )
Case Asc("r") 'Reply
If iKeyReplyNum < 0 Then
Print "ERROR: Reply without Keyword"
EndIf
IsKeyWord = 0 'not a Keyword
sAppend( g_Key_Reply(iKeyReplyNum).Replys(), sText )
End select
Endif
WEND
CLOSE #h
END SUB
FUNCTION checkArray(Array() AS STRING, inpt AS STRING) AS BOOLEAN
var result = 0
dim as boolean Found = false
for i as integer = 0 to ubound(Array)
result = Instr(inpt, Array(i))
if result <> 0 then
Found = True
exit for
end if
next i
RETURN found
END Function
function userQuestion(txt AS STRING) As String
Dim As String rply
For N As Integer = 0 To UBound(g_Key_Reply)
With g_Key_Reply(N)
If checkArray(.Keywords(), txt) THEN
Return .Replys(Int(RND*(UBOUND(.Replys))+1))
End If
End With
Next N
Return "i don't know what to say. sorry."
End Function
loadArrays("database.txt")
Do
Input "> ", Inpt
rply = userQuestion(inpt)
Print rply
Loop Until LCase(inpt) = "quit"
Print "goodbye"
sleep
Code: Select all
k:hello
k:hi
r:hello there how are you doing today?
r:hi. nice to meet you :)
k:i'm sad
k:i am sad
k:i don't feel good
r:i'm sorry to hear that. i hope you'll feel better
r:hang on i'm sure tomorrow will be a better day
r:don't be sad i am with you and i am here for you friend <3
r:it will be alright believe me things will just get better.
k:do you care
k:do you love
k:are you my friend
r:yes i do i am here for you
r:yes i am i believe in you always
r:i am your friend dear one :) your my budd
ron77
p.s. - I hope this link is not considered to be spam :O
okay I removed the link as this was inappropriate