September 19, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Using Microsoft Agent

  • November 19, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

So, you've downloaded Agent and are ready to rock-and-roll?

Great! First let's add our Agent to a sample project:

  • Create a new Visual Basic project
  • Click 'Project', 'References'
  • Find and select 'Microsoft Agent Control 2.0'

Now let's get it to talk:

  • Create the following public variables in the 'General Declarations' section behind your Form:
Dim WithEvents CoreAgent As AgentDim Assistant As IAgentCtlCharacterEx
  • Add a Command Button to Form1
  • Change it's Caption to "Initialise Agent"
  • Insert the following code behind the Command Button:
Set CoreAgent = New AgentCoreAgent.Characters.Load "Assistant"Set Assistant = CoreAgent.Characters("Assistant")

This code simply 'fires up' the agent. The first line creates the main Agent engine object. From this, the second line loads the default character, christening it a very original "Assistant". Finally, the third line of code sets your Assistant object to the newly created character.

It's worth noting that from this point onwards, you only really need to play around with the Assistant object. We've finished our work with the CoreAgent object.

Top Tip: It's worth noting the second line of code also has an optional parameter 'LoadKey'. If you have more than one Agent character on your computer, this is where you can specify which one to use. Just insert the character filename (and a path if not in Windows\MsAgent\Chars), such as "Robby.acs", for example: CoreAgent.Characters.Load "Assistant", "Robby.acs"

Let's continue with the project:

  • Add another Command Button to Form1
  • Change it's Caption to "Start Agent"
  • Insert the following code behind the Command Button:
With Assistant   .Show

.Speak ("Hello! I'm your friendly assistant, Robby!") .Think ("I wonder if he's listening?") .HideEnd With

These fairly guessable methods bring your character to life. Let's see them in action now:

  • Press F5 to run your application
  • Hit the Command Button to test your code

Hopefully the agent should appear on your screen and the passed text be displayed in a speech balloon. If you've installed the Text-to-Speech engine, you'll even hear the Agent speak to you!

Finally, the agent will think out your I-wonder-if-he's-listening sentence in an idea bubble, before finally disappearing. Wahoo!

Top Tip: To change the font used by the speech balloon, set the Assistant.Balloon.FontName property, like this: Assistant.Balloon.FontName = "Verdana"





Page 3 of 7



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel