It is a tradition of all programming to begin a tutorial with a quick view of what can be done in a small script, usually called "Hello world", which does nothing but display the phrase "Hello World".
Far be it from me to break tradition.
To let Hal know that you have made a plugin, you have to tell it a few things first, at the very begining of the file.
Rem Type=Plugin
Rem Name=Hello World
Rem Author=Bill DeWitt
Rem Host=Assistant
The first line tells Hal you have made a plugin instead of something else. It will read all *.uhp files in it's working directory, and any that begin with that line will be treated as a plugin.
The second line is what the General Options > Brain menu selection will show as a Title of your plugin. Of interest is that Hal lists them in alphabetical order of the file name, not the Title.
"Author" should be apparent, and "Assistant" tells it to use the UltraHal assistant, rather than the AIM module or something else.
'-----------------------------------------------------------------
'This sub sets up the plug-ins option panel in Hal's options dialog
'-----------------------------------------------------------------
Sub OptionsPanel()
lblPlugin(0).Caption = "Makes Hal say Hello World"
lblPlugin(0).Move 120, 120, 3300, 1200
lblPlugin(0).WordWrap = True
lblPlugin(0).Visible = True
End Sub
Hal runs this Subroutine as part of the Options dialog. More than anything else, this is why you should (you may find you have to) restart Hal after you have done the first creation of a plugin. This part is really Visual Basic, rather than VBS, and runs with the executable file. Edits can be loaded after startup, but to tell Hal that there is a plugin with a subroutine that needs loading, you have to restart.
If you leave this out, it may still run, but you can't tell your users anything in the options dialog. I also use this to give me the first hint that my script is not working. If you have open parentheses or an 'If' without a 'Then', it won't show the Lable (lbl). This lable has 1 line of text which it displays in the rectangle described by "move" parameters.
The previous was setup, easy to cut and paste. Now it's time to get creative. Not very creative, but creative.
Rem PLUGIN: PLUGINAREA7
HalBrain.ReadOnlyMode = False
If InStr(1,OriginalSentence,"Hello Robot",1) Then GetResponse = "Hello World"
HalBrain.ReadOnlyMode = True
OK, we're done. See you next week... huhwhat? OK, a little more.
Plugin Areas are location in the main script which are marked to allow Hal to insert your endeavors directly into the script. It simply plugs it in (get it?) word for word.
This tells Hal to open his mind and let in some new information. We all know how painful that can be. The read only mode is now false, meaning it's not read only.
InStr() is a VBS function that looks in the string you designate for the exact string of text you specify. In this case, it looks for "Hello Robot" in the string OriginalSentence, which is the sentence you will speak or type into Hal to test this plugin.
| I used 'Hello Robot' to assure that you used a phrase that is not common, if this is a common one for you, make up something else |
Your sentence into Hal is the original sentence, Hal's back to you is contained in GetResponse. IF you say "Hello Robot" THEN Hal will say "Hello World". Don't worry about the "1" or the "1"... you can look them up later or keep reading.
So now we have Told Hal that we made a plugin, we set up a lable for the options dialog, we slipped our script into PLUGINAREA7, we opened up the database for editing, we told Hal that if it hears the words 'Hello Robot' it should reply with 'Hello World', so all that is left is to shut the door on the database...
... and go test our plugin. Save it as "Hello.uhp" in your UltraHal directory (Using the wrong directory seems to be a common error) restart Hal and activate the plugin.
To activate the plugin you have to click on Menu or right click the Hal icon in the Task Tray, choose General Options, click on Brain, and put a check mark in the little box next to your plugin title in the right hand text box. Press OK and then click on the icon to bring Hal back up. Type in (don't speak it in unless you have good accuracy with voice recognition. If it fails, I want it to be for a scripting reason, not a VR failure)... Ooo the tension... type in... "Hello Robot".
Did it work?
If not, you have to go back and check your typing, captials are important since VBS is case-sensitive. Save it and then go back to General Options. You have to uncheck your plugin, click Apply and OK, then go back in and recheck it. I know... tedious. Just incase, below is the whole plugin as I have it on my machine, working and everything...
Rem Type=Plugin
Rem Name=Hello World
Rem Author= Bill DeWitt
Rem Host=Assistant
'-----------------------------------------------------------------
'This sub sets up the plug-ins option panel in Hal's options dialog
'-----------------------------------------------------------------
Sub OptionsPanel()
lblPlugin(0).Caption = "Makes Hal say Hello World"
lblPlugin(0).Move 120, 120, 3300, 1200
lblPlugin(0).WordWrap = True
lblPlugin(0).Visible = True
End Sub
Rem PLUGIN: PLUGINAREA7
HalBrain.ReadOnlyMode = False
If InStr(1,OriginalSentence,"Hello Robot",1) Then GetResponse = "Hello World"
HalBrain.ReadOnlyMode = True
HTH
- Introduction
- Why I did this
- What this really is
- Who this is for
- Hello World
- Expanding your options
- Varying the response
- 2
- a
- b
- 3
- a
- b
- 4
- a
- b
- 5
- a
- b
- 6
- a
- b
Comments (0)
You don't have permission to comment on this page.