Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Don Ferguson

Pages: 1 [2]
16
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!)

17
Ultra Hal 7.0 / Giving Hal a Real Body
« on: August 30, 2003, 02:19:28 am »
Hal and the computer generate an audio output for the computer speakers, and phoneme information to drive the Haptek, DesktopMates, and MS-Agent lip-synchronized character mouth movements.

In the commercial marketplace, numerous low-cost toys have been sold with lip-synchronized sound.  These include three generations of Teddy Ruxpin talking teddy bears (millions have been sold), many versions of singing fish such as "Billy Bass," and even some little robot songbirds that can sing "Santa Baby" beak-synchronized to Madonna's voice! The talking/singing characters all use an audio track and a second control-tone track to create the lip-synchronized action.

Somebody needs to invent a "black box" interface (probably hooked to the computer with a USB interface cable, and another wire out the other end that goes into the toy) that will translate the computer-available information into a format that could drive some of these talking toys.

The result would be a "body" for Hal!  Once the concept was demonstrated in one toy, it could be adapted to others.

Is anybody out there an electronics hobbyist as well as a software writer and chatterbot enthusiast?  If so, you are the one I'm directing this idea to!

I predict that when and if you invent the "interface box," you are going to find an eager chatterbot community of people who want to buy them from you!

I've searched the Internet high and low.  There's all sorts of information on audio-animatronics of all kinds, but no consumer interface box to connect the computer audio/phoneme stream to an outside device!

I think that we can all visualize how this would work in concept... what we need is someone with the skill-set to make it a physical reality at the detail level... somebody to produce a hookup box as a reasonably-priced "turn-key" product so that anybody can buy it and use it!

Thanks, best wishes for enjoying Hal, and good inventing!

Sincerely,

Don

Pages: 1 [2]