Introduction
In this tutorial, I will be showing you how to make a small program that will help you understand certain aspects regarding Microsoft Agent. In this case. we will be using the Merlin model, because he comes with Windows XP. If you do not have Windows XP, then don't worry. The source code download includes the model and all the installs required to use it (2 small 1MB or so files”), which must be distributed with your program in order for it to work properly on other machines. So let's get started.
First of all, download the source file and install, “INSTALL FIRST.exe” and “INSTALL SECOND.exe”. Once that is done, put “MERLIN.ACS” in the same folder as the one your project is in. So then, let's start coding.
Start a new project if you haven't already done so, and make sure wherever you save it, it is in the same directory as “MERLIN.ACS”. Go to your form and right click the toolbox and press “Components…” you will see a screen much like this one:
As you can see here, I have already selected Microsoft Agent Control 2.0. So, unless it is already done, tick the box, then press OK.
Now you will see the Agent Control in the toolbox (secret agent guy). Go to your form design view, and click the Agent Control, and draw it anywhere in your form (it is invisible to the user).
Next draw a ComboBox
near the top in the center of the form, and name it Animation
, and set text to nothing. Now, draw a TextBox
underneath the ComboBox
and name it Speech
, set its text to nothing. After that, draw a CommandButton
at the bottom, in the center and name it, “btnDoIt
”, and set its caption to “Do It!”. Now just add a Label
next to the Animation ComboBox
and set its caption to “Animation:
”. Add another Label
next to the Speech TextBox
and set its caption to “Speak:
”.
Your form should look something like this:
Now, to the code. Choose Form, Load and you will see...
Private Sub Form_Load()
End Sub
... appear in the code. In between “Private Sub Form_Load()
” and “End Sub
”, type:
Dim CharPath As String
CharPath = ""
ctlAgent.Characters.Load "Merlin", CharPath & "merlin.acs"
Set Merlin = ctlAgent.Characters("Merlin")
Merlin.Show
Animation.AddItem ("Acknowledge")
Animation.AddItem ("Announce")
Animation.AddItem ("Blink")
Animation.AddItem ("Congratulate")
Animation.AddItem ("DoMagic1")
Animation.AddItem ("DoMagic2")
Animation.AddItem ("Explain")
Animation.AddItem ("GestureDown")
Animation.AddItem ("GestureLeft")
Animation.AddItem ("GestureRight")
Animation.AddItem ("GetAttention")
Animation.AddItem ("LookUpBlink")
Animation.AddItem ("MoveDown")
Animation.AddItem ("MoveLeft")
Animation.AddItem ("MoveRight")
Animation.AddItem ("MoveUp")
Animation.AddItem ("Pleased")
Animation.AddItem ("Process")
Animation.AddItem ("Read")
Animation.AddItem ("Sad")
Animation.AddItem ("Search")
Animation.AddItem ("Show")
Animation.AddItem ("Think")
Animation.AddItem ("Wave")
Animation.AddItem ("Write")
This simply adds every animation the Merlin has into the ComboBox
, after activating and showing the Merlin Model. Next double-click the “Do It!” button and type:
Set Merlin = ctlAgent.Characters("Merlin") If Animation.Text = "" Then MsgBox ("No Animation Selected") Else ‘ If something has been chosen in the ComboBox
Merlin.Play Animation.Text End If
If Speech.Text = "" Then MsgBox ("No Text Entered to speak") ‘ Give an error
Else Merlin.Speak Speech.Text End If
End Sub
Now when you run the program, if all goes well (if not, see possible errors later on in this tutorial), then when the form appears, so should Merlin, and you can choose any of his animations, and type in anything for him to say, and he will do it. Pretty cool huh?
POSSIBLE ERRORS
One error I had was to name my project “Merlin”, and that made an error because the model was named Merlin, and whenever I set Merlin’s properties, the compiler thought I was referring to the project.
Also, if you don't install those two files, either the character won't show up, or you won't be able to hear anything he says, you'll just see the text.
I hope you enjoyed this tutorial. If you have any questions or suggestions, feel free to email me at spiderfreak3000@msn.com.
History
- 21st June, 2004: Initial post