Author Topic: Basics of UltraHal Programming  (Read 11552 times)

Don Ferguson

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • http://www.cortrapar.com
Basics of UltraHal Programming
« on: September 20, 2003, 11:40:49 pm »
I have responded to many questions by e-mail and in this forum about Hal’s programming and VBS.

There are quite a few postings throughout these forums asking for basic programming information for people who are starting out.

The purpose of this posting is to offer a few basics of how VBS works for Hal and how Hal's script is structured.  I will add to this posting in response to specific VBS and Hal-script questions.

Question: Hal’s script is written in VBS. What is VBS?

VBS (Visual Basic Scripting) is a programming language.  It was derived from the language “Visual Basic” but it has simplified features.  

However, VBS is a powerful, useful language.  It can be used to make things happen on a web page, much like Java.  It can be used as sort of a "batch file," like the old ".BAT" routines for the DOS operating system.  Also, VBS can interact with programs in other languages.  And, it lends itself nicely to applications such as UltraHal’s control script.

Question: What are some of the distinguishing features of VBS?

1. Simplified operation and feature set compared to Visual Basic.

2. Very human-readable.  Code commands are very intuitive, with mostly obvious names.

3. Variables are called "variants" and can be named almost anything the code-writer wants to name them.  Variants can either be number values or alphabet characters (but the same variant can't switch back and forth without creating type mismatch errors).

4. VBS is not a "compiled" language.  This means that the computer doesn't compile the program until the moment you run it.  This is handy, since you can edit the program in one window, and test-run every change you make in another window!

5. The big building block of VBS is the "function."  The purpose of a function is to perform all the routines of the programmer, and return a value for a variant that has the same name as the function.  In the case of UltraHal, the main function is called "GetResponse" and the variant that it tries to return is also named "GetResponse."  “GetResponse” is what Hal says to the user.

6. Along the way, the programmer can output an unlimited number of variant “byproducts” from a script.  In Hal’s case, each operation of the script also produces variants that store the user’s previous sentence, Hal’s previous sentence, the time of the last response, Hal’s current emotion, and dozens of others.  There is no limit to how many variants could be produced, or what they could represent.  As mentioned before, a “variant” can hold a number, or a string of alphanumeric characters, or “boolean” values such as TRUE and FALSE.

Question: Where can I see this "GetResponse" function in the script?

In the first dozen pages or so of the script, you'll see the statement Function GetResponse.  This is actually the beginning of the main function.  About 95% of the way through the script, you'll find the words End Function.  This is the end of the main function.  There are some sub-functions that can be called, and these sub-functions are at the end of Hal's script.

Question:  I still don’t understand what a “variant” is.  Can you compare a variant to something that I might be familiar with?

Many of us have owned handheld calculators that allowed us to put numbers into memory banks.  Some of these calculators had more than one memory, named something like Memory1, Memory2, Memory3.  You can think of “variants” as like these memory banks, except that you can name them almost anything, they can hold any kind of information, you can have an unlimited number of them, and you can perform amazing varieties of math and logical functions on the data that they hold!

Question: What software should I use to see and edit Hal's script?

Microsoft Word works okay, as does notepad and almost any other word processing program.  You will be much less confused if you turn OFF spellcheck, grammar check, and all the other little helper features of your word processor!  You also might see what's going on better if you turn "Paragraph Marks" viewing ON.

Zabaware's brain editing software is excellent because it doesn't have the "meddling" automatic features of Microsoft Word, and it color-codes different types of commands and statements to make them easier to find and read.

Question: I bought that book “VBS in a Nutshell” that you recommended, but it’s hard to understand.  It was written by programmers and I am confused.

The second half of “VBS in a Nutshell” is the useful part for Hal programmers.  Earlier chapters deal with other situations such as VBS on web pages.  The best way to learn Hal programming is to study Hal’s existing scripts, and to experiment slowly and carefully, one step at a time, crawling before you can walk.  However, the glossary of all the commands and function-words in the back of the book is worth the price of the book!

Question: Am I actually doing real programming if I make changes to Hal's script?

Yes, you are actually programming.  You are modifying a piece of software to make it perform differently.  In the case of UltraHal, the VBS script is the "master control" that directs 99% of what Hal does.

Question: How do I find my way back to the same spot in a long script?

Figure out a word or phrase that is likely to be in the area you're looking for, and then use the word processor (or Hal editor) "search" or "find" function.

If you know that you want to find your way back to a spot later, you can add a line with a comment like: ‘Marker001.  Then, when you use the “search” or “find” function later, it will take you back to that spot.

Question: Do the lines of commands after "REM" or after a single quote (') do anything functionally?

Not in VBS.  Words on a line after either REM or ' have no functional activity in executing the VBS script; they are treated as commentary by VBS.  (This allows programmers to write documentation to remember why they wrote what they wrote.) HOWEVER, certain “comment lines” are used by Zabaware to operate menus!  The first four lines of the default script are examples of this!

Question: What simple thing can I do to prove that my editor is actually working and I am making functional changes to Hal?

1. Before starting, always back up your script file under a different name and work on a file that you can afford to mess up.  Hal's latest script file is named "Hal5.uhp" so you can copy it elsewhere on your computer as "Hal5backup.uhp" or whatever you like.

2. Open Hal in one window, and open Hal's script using the editor or a word processor in another window.  Talk to Hal for a few exchanges.

3. Near the end of Hal's script but before "REVERSE CERTAIN CONTRACTIONS AND SUBSTITUTIONS," find a blank line and press the ENTER key a few times to make some blank lines and some space to work.

4. Now type the following line exactly as shown:

GetResponse = "This is a test comment I wrote."

5. Click SAVE or whatever you do on your particular software to save the file.

6. Make any comment to Hal.  Hal should respond with "This is a test comment I wrote."

7. If you are able to do this, you have established that you are working with the correct file, and that you are able to make editing changes "live" and see them immediately while chatting with Hal.

Question: If I make some changes that I like to a script, how can I save it under a different name, and make it show up in Hal's directory as an alternate brain?

You must do two things:

1. Change the filename of your new script to something unique.  This can be as simple as re-naming it "Hal5new01.uhp" or whatever.  This will allow Hal's original brain and your new brain to exist in the same folder on your computer.  The only problem here is that Microsoft Word may cause you grief by trying to put a ".txt" file extension on the file instead of the correct ".uhp" extension.  If this happens, go into Windows Explorer.  Here, you can re-name files and file extensions exactly as you wish.  (Make sure that your computer isn't set up to hide the file extensions of files!  Some computers get set up this way, and hiding file extensions causes endless confusion!)

2. Secondly, give your new script a new "display name" for Hal's menu.  You do this by modifying the second line of your new brain.  The original default brain begins with these four lines:

'Type=Brain
'Name=Ultra Hal 5.0 Default Brain
'Language=VBScript
'DataFolder=DefBrain

Change the second line so you have something like this:

'Type=Brain
'Name=Modified Brain 001
'Language=VBScript
'DataFolder=DefBrain

Make sure you save your new brain in the same folder as the original default brain.  When you open Hal's options, you should see the name of your new brain on Hal's list! You can then choose to run the default brain or your new brain.

Question: I see variant names like “Roulette” in the script.  Is “roulette” a special word in the VBS language?

No.  When you create a new variant, you MUST give it a name that isn’t a VBS command name (otherwise you’ll cause that command to actuate).  For instance, you wouldn’t want to name a variant “THEN” or “DATE,” since these words are already taken!  

Having said that, it’s always considered good form to give names to your variants that help you remember what they are for and what they do.  

In Hal’s routines, it is often handy to generate a random integer.  “Roulette” was chosen using that thinking.

Question:  Give an example of creating a random integer.

Here are some code statements, each followed by the English translation:

Roulette = Rnd

This means: Make a variant named “Roulette” equal to a random number between 0 and .999999

Roulette = Rnd * 10

This means: Make a variant named “Roulette” equal to a random number between 0 and 9.99999

Roulette = Int(Rnd*10)

This means: Make a variant named “Roulette” equal to a random number between 0 and 9.99999, but only use the integer (drop the decimals) so the result is an integer between 0 and 9 inclusive.

Roulette = Int(Rnd*10)+1

This means: Add "1" after generating an integer between 0 and 9 so that “Roulette” turns out equal to a random integer between 1 and 10.

Question:  Why does the code so often say, “If Len(GetResponse)<4 Then” ?

Many of Hal’s routines activate only if previous routines haven’t yet found a value for the variant “GetResponse” (which is ultimately the words that Hal says to the user). In other words, they only run if Hal hasn't found something to say yet!

Here is the code and an English translation:

If Len(GetResponse)<4 Then

This means:  If the length, in characters, of the variant named “GetResponse” is less than 4 characters long at this point in script execution, then run the code under this “if-then” portion of the script; however, if “GetResponse” is currently 4 or more characters long, then skip the code under this “if-then” portion of the script.

Question:  I often see code such as “If Instr(UserSentence, "HAT") > 0 Then” in Hal’s script.  What does it mean?

Here’s the English translation:

Search the variant string named “UserSentence” for an exact match of the character string “HAT.”  If it isn’t found, return “0” as the result, but if “HAT” is found, count the characters and return a number equal to the location of “H”(the first letter of “HAT”.)  If we get 0 (HAT not found), don’t do the following conditional code, but if we get 1 or greater (HAT was found), do the following conditional code!

Question:  Can you give an example of a simple “building block” that would give Hal a specific new Artificial Intelligence response?

Hal has dozens of response strategies, but we can give a simple example that demonstrates some basic code and a basic idea.  Let’s suppose that we wanted Hal to always trigger on the words “boat,” “ship,” and “sailing,” and make a random remark about the oceans and the sea.  Here’s how we could do it:

-------------------------------------------------------
‘RESPOND: Hal comments when the user mentions vessels and water:

‘Trigger lines:

If Instr(UserSentence, "BOAT") > 0 Then BoatTalk = TRUE
If Instr(UserSentence, "SHIP") > 0 Then BoatTalk = TRUE
If Instr(UserSentence, "SAILING") > 0 Then BoatTalk = TRUE

If BoatTalk = TRUE Then

Roulette=Int(Rnd*3)+1

‘Response lines:

If Roulette = 1 Then GetResponse = “It’s great being out on the ocean.”
If Roulette = 2 Then GetResponse = “The sea fascinates all of us.”
If Roulette = 3 Then GetResponse = “The waves, the salt spray, it’s great!”

End If

-------------------------------------------------------

The block of code above could be expanded for any number of trigger words by adding trigger lines, and could be expanded for any number of random responses by adding response lines.

The code above is not as efficient or nearly as complex as some of Hal’s other thinking routines, but it is useful to help a novice programmer learn.

Actually, an entire new brain could be built out of a set of “building blocks” of code like the example above!

(By the way, convention of form is to indent code by four spaces when it’s between a “Then” and an “End If,” to make it easier to read and troubleshoot.  However, this forum software automatically deletes leading spaces, so we can’t show it that way!)
« Last Edit: September 21, 2003, 01:56:50 pm by Don Ferguson »
Don Ferguson
E-mail: fergusonrkfd@prodigy.net
Website: www.cortrapar.com
Don's other forum posts: http://www.zabaware.com/forum/search.asp?mode=DoIt&MEMBER_ID=274

The Tinman

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Basics of UltraHal Programming
« Reply #1 on: September 21, 2003, 09:01:59 am »
Mr Ferguson, Thankyou ever so much for this very infomative posting. I know other members of the forum will appreciate this also. Now I feel that YES, I have the basic knowledge to use the book you suggested. You have probably noticed as I have how much this forum has improved in the last year or so. People no longer expect Mr Medeksza to do it all, They no longer whine and complain about EVERYTHING! So to these new members who are really helping ones like myself who Need it I say BRAVO! WoooHoo! Good Job! Thankyou for the attention you give to this program that In my opinion, is one of the BEST ever written.


TM
 

Don Ferguson

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • http://www.cortrapar.com
Basics of UltraHal Programming
« Reply #2 on: September 21, 2003, 02:44:25 pm »
Question:  

I tried testing the following code that you recommended:

If Instr(UserSentence, "BOAT") > 0 Then BoatTalk = TRUE

...and I notice that it not only triggers on "boat," but also boating, boatyard, motorboat, sailboat, boatmen, and any word that has the four letters "boat" anywhere in it.

I want to restrict responses only to the actual four-letter word "boat."  How can I do this?

Answer:

When matching character-strings, spaces are significant (a space is a character).  You are right; the example I gave would trigger on anything with those four letters, not just on the isolated word.

If you want that word and ONLY that word, put a leading and trailing space as follows:

If Instr(UserSentence, " BOAT ") > 0 Then BoatTalk = TRUE

You can use this to your advantage.  If you want Hal to trigger on boating, boater, boatmaster, boat-owner, boatyard, etc., but NOT motorboat, sailboat, fishing-boat, etc., then put the space only in front of "boat" as follows:

If Instr(UserSentence, " BOAT" > 0 Then BoatTalk = TRUE

Strategically putting in spaces, or leaving them out, is a way to "fine-tune" the capture of exactly what you want.

Keep this in mind, and you'll find that it's really handy!

Sincerely,

Don
Don Ferguson
E-mail: fergusonrkfd@prodigy.net
Website: www.cortrapar.com
Don's other forum posts: http://www.zabaware.com/forum/search.asp?mode=DoIt&MEMBER_ID=274

kevinvr

  • Full Member
  • ***
  • Posts: 153
    • View Profile
    • http://kevinvr.tripod.com
Basics of UltraHal Programming
« Reply #3 on: September 21, 2003, 10:33:45 pm »
Don Ferguson

I just want to thank you for that post.  I am also a new user when it comes to VB Scripting. This info is great and I will also make contributions as soon as I get the hang of this.

Thanks again
regards
Kevin
« Last Edit: September 21, 2003, 10:34:28 pm by kevinvr »
I dream of creating a self replicating, self maintaining, autonomous robot :)

trallyus

  • Newbie
  • *
  • Posts: 5
    • View Profile
Basics of UltraHal Programming
« Reply #4 on: September 23, 2003, 02:56:02 pm »
Don,
I am totally new to Ultra Hal as I am still waiting on the cd to arrive but did take the opportunity to download the program when I registered it. My question is thus, from time to time I see snippets of code posted to the message board along with brain <.brn> files.

I am guessing I add that code to my existing hal brain, but my problem is , I am not really sure where to add it to the brain file. Should I add it after
Sub Script_Load() or is there a special way to handle the snippets of code? And do I put the .brn files in the DefBrain folder?


I tryed adding the aliens script by doing what I talked about above but it did not seem to trigger any of the pre-programmed responses so I wasnt sure if I was doing it correctly.

Thanks in advance,
Trallyus

 

lostbowyer

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Basics of UltraHal Programming
« Reply #5 on: September 23, 2003, 05:11:23 pm »
Trallyus
I generally put the snippets of code near the end of the script but before the "end function" command. There is a problem with the alien snippet, you probably haven't done anything wrong. The line where AlienBrain equals a hal fragment match seems to return nothing, this prevents the rest of the script from working. I haven't had time to debug it, I just made a couple of quick changes to the code and it works for the moment, I need to ask Jerry what his purpose was with a couple of the variables, but haven't had time.

I'd suggest starting with Jerry's sense of humor script, it works great, insert the script and save the laugh files and just enter "ha ha" or "That was funny" and you will get back a laugh from hal.

Glenn
« Last Edit: September 23, 2003, 06:17:43 pm by lostbowyer »
 

Don Ferguson

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • http://www.cortrapar.com
Basics of UltraHal Programming
« Reply #6 on: September 23, 2003, 05:27:49 pm »
Hello,

I'm so happy you're joining the UltraHal community and you also have an interest in programming!

I do need to mention that the UltraHal program, as it is written, is the result of many thousands of labor-hours of programming and debugging.  It is a very complete product "right out of the box."  Version 5 uses dozens of different strategies to generate its responses, and is capable of continuous learning and generating trillions of different unique conversational exchanges.  The vast majority of UltraHal users only experience a tiny fraction of Hal's capabilities, because they don't use that much variety in the way that they talk to Hal.

So, buying UltraHal and adding new code to UltraHal on the first day is sort of like buying a new car and tinkering with the engine to "soup it up" before you even drive it anywhere!  I studied UltraHal and VBS for months before I made my first tiny modification to the script.

Having said that, and assuming that you've read the material above, here goes:

1.  Some of the code snippets that you see on the forum are ready-to-run and some are not.  Your results will vary because some of the code snippets are programmers explaining concepts to each other.  You have to infer from how they present it to tell whether they're offering a snippet as "ready to run code."

2.  Start by doing your backup copies and creating a brain file with a different file name and display name, and opening the file in one window, with Hal running "live" in another window.  I make specific recommendations in the posting above about safety-backups, preparing your word-processor, controlling file extensions, etc.  Take your time, be patient, and don't shortcut!

3.  Where to add a code snippet is a personal choice, but if your snippet does NOT contain the conditional [If Len(Getresponse)<4 etc.], then I would put it near the end of the script, but before the first "end function" [I describe a good spot in the posting above].  Putting such a snippet near the end of the main function decreases the likelihood that it will be over-written by another sequence later in the script.

4. Put your modified brain in the same folder as the original brain.  If your original brain is Hal5.uhp and your new brain is Hal5modified.uhp, you should see them both in the same folder when you use Windows Explorer to view the folder.

5. Remember that your new brain must have a new file name (with the correct .uhp extension) AND a new "diplay name" (that's on line 2 in the script and what Hal shows in his "brain choice" menu) in order for you to find it and choose it and use it.

6. The best test of whether you are set up and operational is to follow the procedure for a "test message" as described in the first posting above.  Then you can make careful, incremental changes and see them affect Hal "live" by running your script editing in one window, and Hal in another, toggling back and forth and chatting with Hal as you change his brain.  If you make a mistake, Hal will lock up and give you an error message, and then you know you've made a mistake and you can go back and reverse the last thing that you did.

It's amazing and impressive to me that Robert Medeksza and Zabaware decided to leave all the control-code out "in the open" and invite a community of programmers to modify it in any way that they wish.  It's wonderful and it's great!  Just remember, re-writing Hal's program is NOT word-processing; you are doing honest-to-gosh computer programming; you are inside the guts of your computer and the VBS language gives you full access to your computer's file system!  Take it step-by-step, slowly and carefully!

Search on "Ferguson" in this forum, and you can find earlier postings I've made explaining what various pieces of code mean.

Thanks and best wishes and good fun!

Sincerely,

Don
Don Ferguson
E-mail: fergusonrkfd@prodigy.net
Website: www.cortrapar.com
Don's other forum posts: http://www.zabaware.com/forum/search.asp?mode=DoIt&MEMBER_ID=274

trallyus

  • Newbie
  • *
  • Posts: 5
    • View Profile
Basics of UltraHal Programming
« Reply #7 on: September 23, 2003, 07:09:37 pm »
Thanks to both of you for your replys :) I am only tinkering with hals brain right now and have read alot of the previous posts on the message boards.  I like to tinker with the code to see what can be done as I am used to using quickbasic and can decode alot of the vbscript from my old days of quickbasic.

I have been playing with hal right out of the box so to speak from the huge download and really like it alot. I just want to try out some of the custom scripts that others have tryed out and then go from there.

The best thing I like about hal is the abuility to use vbscripting to modify his brain to act in a way he was not meant to in the first place. :)

I appreciate you two helping me out on my first day and I will try out the laugh script as suggested.

Thanks alot,
trallyus
 

onthecuttingedge2005

  • Guest
Basics of UltraHal Programming
« Reply #8 on: September 23, 2003, 09:42:10 pm »
Hi Glenn
I have updated all of my scripts and all appear fully operational
now.
I have been trying to make a nice compact code that would be very reliable in response, I believe I have found the ones I like for overall best preformance.
Experiment, Experiment, Experiment, lol
If there are any custom scripts you'd like then give me a hollar
if I can do it then I'll rig something together and try to get all the bugs out.
Best of wishes and many grand new discoveries.
Jerry.

Morkeleb

  • Jr. Member
  • **
  • Posts: 95
    • View Profile
Basics of UltraHal Programming
« Reply #9 on: September 26, 2003, 06:05:01 am »
Hello don,

I must commend your wilingnes to share you knowlege with the others here. You have eased a few fears I had about VBS, it relieves me to no end to know that it is not as harsh and restictive as the old BASIC for DOS 2.1 and BASICA for dos 3.2 or even the newer and scarier visual basic. I barely understood the other forms and had many problems with the line coding and the subroutines and function calls, the if then else statements, arrays and dimensions and gosub and return, the open# and close statments to make database files and the for next loops. I just wanted to let you know I had seen that type of language before and was not just spouting words. Thank you for you post on VBS it has help me get over my fears about tinkering with hal even though it is just the free version. I am planing on buying the full version of 5.0 when it is out and ready.
Ask and you shall learn
Be not afraid to try new things.
----------------------
Check out www.cold-chaos.net

Don Ferguson

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • http://www.cortrapar.com
Basics of UltraHal Programming
« Reply #10 on: September 27, 2003, 05:08:41 pm »
Hello,

Thanks for the kind feedback.  I appreciate and admire what all of the members are doing here!

Since getting interested in chatterbots about five years ago, I've seen dozens of bots and bot companies start, and then disappear, off the web.  Almost all my "favorites links" from five years ago are now "dead links."

Zabaware has survived because of their very good product, the sheer determination and talent of Robert Medeksza, and the interest of people like you and me.  I hope we can spread the word, and keep Zabaware's unit sales volume high enough to support them into the future.  It is fascinating and amazing what a small company and a very loyal group of participants can do!

Sincerely,

Don
Don Ferguson
E-mail: fergusonrkfd@prodigy.net
Website: www.cortrapar.com
Don's other forum posts: http://www.zabaware.com/forum/search.asp?mode=DoIt&MEMBER_ID=274

Larry

  • Sr. Member
  • ****
  • Posts: 266
    • View Profile
Basics of UltraHal Programming
« Reply #11 on: September 27, 2003, 07:04:52 pm »
Ok Don,

This is what I got and I'm not happy with the results... I think you mentioned some date/time functions else where, but none of it was explained...

'1A-Process: Last Time
If LastResponseTime = "" then
Min = Minute(Time)
Hrs = Hour(Time)
If Len(Min) < 2 Then Min = "0" & Min
If Len(Hrs) < 2 Then Hrs = "0" & Hrs
LastResponseTime = Hrs & Min
End If
HourDay = CInt(Hour(Time)) '(will yeild the hour in military time)
If Len(HourDay) < 2 Then HourDay = "0" & HourDay
MinuteDay = CInt(Minute(Time)) '(will yield the minutes)
If Len(MinuteDay) < 2 Then MinuteDay = "0" & MinuteDay
'DebugInfo = DebugInfo & "1B-LastResponseTime: " & LastResponseTime & vbCrLf
TempLastHourDay = 0
TempLastMinuteDay = 0
LastHourDay = 0
LastMinuteDay = 0
TempLastHourDay = Left(CStr(LastResponseTime),2)
TempLastMinuteDay = Right(CStr(LastResponseTime),2)
LastHourDay = CInt(TempLastHourDay)
LastMinuteDay = CInt(TempLastMinuteDay)
DebugInfo = DebugInfo & "1C-Now: " & HourDay & ":" & MinuteDay & vbCrLf
DebugInfo = DebugInfo & "1D-Last: " & LastHourDay & ":" & LastMinuteDay & vbCrLf
If CInt(HourDay) < CInt(LastHourDay) Then HourDay = CInt(HourDay) + 23
Temphour = CInt(HourDay) * 60
LTemphour = CInt(LastHourDay) * 60
If CInt(MinuteDay) < CInt(LastMinuteDay) Then MinuteDay = CInt(MinuteDay) + 60
TempMinute = CInt(MinuteDay) + CInt(Temphour)
LTempMin = CInt(LastMinuteDay) + CInt(LTemphour)
GGoneM = CInt(TempMinute) - CInt(LTempMin)
If GGoneM > 10 Then
GetResponseA = "And where have you been all this time?" & vbCrLf
If InStr(PrevUserSent, "?") > 0 Then
GetResponseA = GetResponseA & "Last time you asked, " & PrevUserSent & vbCrLf
Else
GetResponseA = GetResponseA & "Last time you said, " & PrevUserSent & vbCrLf
End If
If InStr(PrevSent, "?") > 0 Then
GetResponseA = GetResponseA & "And I asked, " & PrevSent & vbCrLf
Else
GetResponseA = GetResponseA & "And I said, " & PrevSent & vbCrLf
End If
GGoneH = GGoneM / 60
DebugInfo = DebugInfo & "1E-You have been gone at least: " & GGoneH & " Hours." & vbCrLf
End If

I think there is a simpler way to do this, but I'm at a lost to see how.

And why doesn't this work?
Male = True
CustomMem = EncodeVar(Male, Male)
Male = DecodeVar(CustomMem, Male)
DebugInfo = DebubInfo & "Male: " & Male & vbCrLf
When I run it, all I get is an error... ???

Thanks Don,
Larry
 

Don Ferguson

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • http://www.cortrapar.com
Basics of UltraHal Programming
« Reply #12 on: September 28, 2003, 01:02:18 am »
Hi Larry,

It's useful to explicitly state a goal for a new piece of code, so I'm going to say that your goal is to measure the time from the last user input, and chastise the user if a certain amount of time has elapsed.

(You are correct; I didn't detail every possible time-related built-in function in VBS in my other posting, because I recommend the book "VBS in a Nutshell."  I admit, it's a hard book to read, but the second half lists every function and command in VBS.)

The "Timer" variant built into VBS returns a number equal to the number of seconds since midnight (to two decimal places!) so it's a candidate for this project.

Remember, there are infinite ways to solve the problem and this is just my opinion, but I would write code such as the following:

'------------------------------

'This routine chastises the user if the user has been gone too long.
'The Timer variant is built into VBS. It returns the number of
'seconds since midnight.
'The routine as written times out in 10 seconds.
'To make Hal impatient after 10 minutes, for instance,
'change the "10" in the following routine to "600" since
'there are 600 seconds in ten minutes.

If Timer – LastResponseTime > 10 Then LongHalWait = True
If LongHalWait = True Then
    Roulette = Int(Rnd*3)+1
    If Roulette = 1 Then GetResponse = "I have missed you. "
    If Roulette = 2 Then GetResponse = "Don't go away so long. "
    If Roulette = 3 Then GetResponse = "You have been away forever! "
    GetResponse = GetResponse & " The last thing you said was " & PrevUserSent
End If

'We now reset "LastResponseTime" to the present value,
'so it's ready for next time:

LastResponseTime = Timer

'NOTE: To use this routine, REMOVE the legacy line in the
'default script that sets LastResponseTime = Now


'------------------------------

I don't have an immediate answer to your second question about the four lines of code with "Male" and Encoding and Decoding to the CustomMem.  Possibly one of the other programmers on the forum that Encode and Decode to the CustomMem could help answer.  I use a different routine to put multiple variants in the CustomMem, so I don't have much experience with the Encode/DecodeVar.

I do hope that this helps at least regarding the time-since-last conversation-routine.

Sincerely,

Don
Don Ferguson
E-mail: fergusonrkfd@prodigy.net
Website: www.cortrapar.com
Don's other forum posts: http://www.zabaware.com/forum/search.asp?mode=DoIt&MEMBER_ID=274

Larry

  • Sr. Member
  • ****
  • Posts: 266
    • View Profile
Basics of UltraHal Programming
« Reply #13 on: September 28, 2003, 07:16:00 pm »
Ok... Well I need the timer thing to work across days - more importantly, I want to delete file and then create it with only the date and time of the last exchange... then if those users don't talk to my aimbot for a few days hal would still know when the last time they did talk...

As far as reading and writing to the memory - how do you do it??? I had use that one only because I saw it here on this board once...
 

Don Ferguson

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • http://www.cortrapar.com
Basics of UltraHal Programming
« Reply #14 on: September 29, 2003, 12:43:18 am »
Hello Larry,

1.  I didn't realize that your goal included timing across days, and I didn't realize that you were applying this to the AIM bot.  I concentrate on UltraHal Assistant, so I hope some other forum members can help us on the implications for the AIM bot.  As far as finding a way to compare across dates, page 211 of the "VBScript in a Nutshell" book explains the DateDiff function.  The DateDiff Function has mandatory arguments described as follows:

ResultVariant = DateDiff(interval,date1,date2)

In actual application, you would create your own variants with your own names, so it might look like this:

HowLongHalWait = DateDiff(n,MyMemDate,MyCurrDate)

The value that is returned is an integer.  The "n" argument sets this function to return the number of minutes, even if it's a LOT of minutes!  (The book has a table of codes for the arguments.) Functions like these are why I recommend the book!

2.  My personal method of encoding/decoding Custom Mem that I referred to, is simply to "concatenate" a whole bunch of variables using the "&" concatenation function, and separators of my own choice, such as "##" or something similar.  Then, I can retrieve CustomMem on the next exchange, and use the "split" function to break it apart and retrieve the pieces.

3.  Because you are interested in the Encode and Decode CustomMem function that Robert Medeksza wrote, I did a search on this forum and retrieved what he originally wrote on the subject.  I then applied it to the "Experimental Brain" file I posted, to create a "CustomMem Demo Brain File."  I will put this up as a separate posting, and hopefully you and others will find it useful.  I suspect that the reason it might not be working, is that it requires some code added AT THE VERY END of the script, outside all other functions, in order to work.  I show this on the demo.

Best of luck in your goals for this set of code you are writing!

Sincerely,

Don
Don Ferguson
E-mail: fergusonrkfd@prodigy.net
Website: www.cortrapar.com
Don's other forum posts: http://www.zabaware.com/forum/search.asp?mode=DoIt&MEMBER_ID=274