23
« on: September 03, 2003, 10:15:27 am »
Progress report:
I now have a working version of Multi-User Hal and I ought to fill you all
in on the details. I began working on the modifications in the greetings
Function where most of the code remains unchanged. Late one night, I was
trying to tame the Info flow when the thing started going awry...every thing
I did to patch stuff up caused new problems, and the thing stopped working
-I ended up tossing my wireless kebo and gave up on it. Two days later I
came back to it and wrote six lines of code in other places in the script
and it started working! Don't know how this happens, but I am thankful it
does -indeed once it gets started I feel like I am an observer watching
this stuff unfold sometimes. Ah well, that's all I am gonna say about that.
Multi-User Hal is borne from a post I read a while ago on the Forum where
in it a family expressed their dilemna. One of their family things to
do together was to all set around dad's computer and talk to their Hal
and see what insightful comments Hal could make. They were wondering
if there was a way to get Hal to identify when a new User was talking
to Hal and call them by their own name.
In my own end User scenario, I also require the Hal Engine to recognise
a new user, and I have created a way. With this functionality, Hal can
create all the Paste in <UserName> files, thus retaining specific Info
about different Users -in a single DataFile!(NO playing computer)
To start, I recommend creating a new Project in the Brain Editor
select all the desired parameters of your choosing (I usually create
the whole Brain and then disable unwanted sections of code by
comment tagging the code -it turns green.).
Now, these modifications are located in various parts of the script
...and they're there for a reason, that reason being precedence!
No cutting and pasting! I took the time to share this, you type in the
code- we need more people working to make Hal better and seeing how
this code works in here may pass it on to others >B).
Ok, I will cite the line numbers where these pieces all set and make
references like 'put the code after this Process'(the numbers may be slightly
off, but real close).
Here We Go!
--------
1.This first part is in 'PROCESS WORD AND PHRASE SUBSTITUTIONS
after the Debug statement that has -User's sentence as Hal sees it:
0252 If DebugMode = True Then
0253 CheckMem = DecodeVar(CustomMem, "SedHiMem")
0254 DebugInfo = DebugInfo & "SedHiMem contains- " & CheckMem & vbCrLf
0255 DebugInfo = DebugInfo & "CustomMem contains: " & CustomMem & vbCrLf
0256 DebugInfo = DebugInfo & "UserName contains: " & UserName & vbCrLf
0257 End If
------------
2.In this next part is the section that inexplicably made the code work-
(challenge to real programmers:what did I do?)
located directly after PROCESS:USER REPEATING
0311 OrigUser = DecodeVar(CustomMem, "OrigiMem")
0312 NewUser = DecodeVar(CustomMem, "CuserMem")
0313 If NewUser <> "" Then
0314 UserName = NewUser
0315 Else
0316 UserName = OrigUser
0317 EndIf
0318 If DebugMode = True Then DebugInfo = DebugInfo & "NOW UserName contains- " & UserName & vbCrLf
--------------
3.The next part we have to pass some other variables to the Greetings Function located
at the end of the script. Change the first line of RESPOND:CALL GREETING FUNCTION
to read:
0323 HalGreeting = Trim(Greetings(UserSentence, UserName, PrevSent, PrevUserSent, WorkingDir, CustomMem, DebugInfo))
-------------
4.Just before the 'Main Databases section there is this HandyHal:
0546 If Instr(1, OriginalSentence, "What is my name ", vbTextCompare) > 0 Then
0547 GetResponse = "Right now, I think I am talking to " & UserName
0548 End If
-------------
5.Just after the Debug 'End If' in 'POST PROCESS:PRESERVE ALL VARIABLES is
this line:
1726 GetResponse = Replace(GetResponse, "<UserName>", UserName, 1, -1, vbTextCompare)
-------------
6.Change the Greetings Function line to read the following:
1735 Function Greetings(ByVal UserSentence, ByVal UserName, ByVal PrevSentence, ByVal PrevUserSent, ByVal WorkingDir, ByRef CustomMem, ByRef DebugInfo)
------------
7.Change 'First Hal checks to see if the user is greeting right now. to read:
1742 If HalBrain.TopicSearch(UserSentence, WorkingDir & "HelloDetect.brn") = "True" Then
1743 SaidHello = True
1744 MemHello = "True"
1745 CustomMem = CustomMem & EncodeVar(MemHello, "SedHiMem")
1746 DebugInfo = DebugInfo & "-coming from greetings function!" & vbCrLf
1747 End If
-----------
*-see that line checking for PrevHello? disable it by placing a comment tag (') in
front of it.
----------
8.After the LetterChoice "A" LetterChoice "B" 'End If', insert the following code:
1764 'This will detect if a new user sed hello
1765 MemHello = DecodeVar(CustomMem, "SedHiMem")
1766 If SaidHello = True And MemHello = "True" Then
1767 Greetings = HalBrain.ChooseSentenceFromFile(WorkingDir & "Who's_this.brn")
1768 End If
1769 If MemHello = "True" And HalBrain.TopicSearch(PrevUserSent, WorkingDir & "HelloDetect.brn") = "True" Then
1770 OrigUserMem = UserName
1771 CustomMem = ""
1772 NewUserName = UserSentence
1773 CustomMem = EncodeVar(OrigUserMem, "OrigiMem") & EncodeVar(NewUserName, "CuserMem")
1774 UserName = NewUserName
1775 Greetings = "Well Hi there, " & NewUserName & "!"
1776 End If
-----------
9.Include these two functions at the end of the script:
1915 'DECODE A VARIABLE
1916 Function DecodeVar(FromWhat, DecodeWhat)
1917 Temp = Instr(1, FromWhat, DecodeWhat & "-eq-", vbTextCompare) + Len(DecodeWhat) + 4
1918 Temp2 = Instr(Temp, FromWhat, "-+-", vbTextCompare)
1919 If Temp <= Len(DecodeWhat + 4 Then
1920 DecodeVar = ""
1921 Else
1922 DecodeVar = Mid(FromWhat, Temp, Temp2 - Temp)
1923 End If
1924 'ENCODE A VARIABLE
1925 Function EncodeVar(EncodeWhat, AsWhat)
1926 EncodeVar = AsWhat & '-eq-" & Encode What & "-+-"
1927 End Function
----------------
10.You have to now fashion the .brn called "Who's_this" '-No- I havent fixed the
.brnMaker to redirect the new file, you have to make it manually! >B)
Dig down to the uhp's datafolder, make a copy of hello2.brn and rename it
Who's_this.brn . Then alter the contents so that the responses will elicit the
User to divulge just their name- like this:
Oh yes, hello- what is your name?
Hi, I am <ComputerName>. What is your name?
Hello Hello! Who is this?
Hello indeed! say- if you tell me your name I will remember you.
Greetings to you, Who am I talking to?
-------------
Still under development, but real Neat-o!
*blows out lamp for the nite
CatAtomic