October 22, 2016
Hot Topics:

Beginning MS Agent: Part 3

  • November 19, 2002
  • By Mack Male
  • Send Email »
  • More Articles »

The method I am going to over is quite simple, yet very effective. As you may have noticed, Agents have a pop-up menu, accessible by either right-mouse clicking on the character or the character's tray icon. This menu will always have the "Hide" or "Show" option. It is quite simple to add a menu item:

Agent.Characters("CharacterID").Commands.Add Name, _                      Caption, Voice, Enabled, Visible

Placing the above line after the lines for loading your character inside the Form_Load procedure will add the command to your agent's pop-up menu. Lets go through the above line, piece by piece.

- Agent.Characters("CharacterID").Commands.Add
Obviously, the first part makes reference to the character you wish to add the command to. The ".Commands" part of the line references the agents commands collection, where all of the available commands are stored. Finally, ".add" allows you to add a new command to the collection. Other methods of the Commands collection are Insert, Remove, and RemoveAll.

- Name
Required. This value is the name of the command, and is used to identify the command. This will be extremely important later on.

- Caption
Optional. This value contains the text that will be displayed on the characters pop-up menu.

- Voice
Optional. This string value corresponds to the words or phrases that the user can say to allow the Speech Engine to recognize this command.

- Enabled
Optional. This Boolean value determines whether or not the command is enabled. The default value is True.

- Visible
Optional. A Boolean value that determines whether or not the command will appear in the characters pop-up menu. The default is True.

Lets go over an example of adding a command.

Private Sub Form_Load()Agent1.Characters.Load "Peedy", _"e:\winnt\msagent\chars\peedy.acs"Set Assistant = Agent1.Characters("Peedy")Assistant.Commands.RemoveAllAssistant.Commands.Caption = "Assistant Commands" Assistant.Commands.Voice = "Assistant Commands"Assistant.Commands.Add "ACO", _        "Advanced Character Options", _        "[Advanced Character Options][Advanced]"Assistant.ShowEnd Sub

As you can see I have loaded the Peedy character in my application. Before adding a new command however, I have added a couple of more lines. As you can see, I have called the "RemoveAll" method which clears the agent's commands so that I can properly add new ones. Next I have changed the caption and voice properties. This is so that the commands I add will appear in the Commands Window (accessible by opening the character's pop-up menu). Finally, I have added a command called "ACO" and called the character's show animation. For my new command, I have entered a caption property, so that the command will appear in the pop-up menu. I have also entered a string for the voice property, so that I can access this command using voice. Lets look at this in more detail.

"[Advanced Character Options][Advanced]"

As I said before, the voice property defines the words or phrases that can be used to access the command. Here I have added a phrase and a word that can be spoken to access this command. The reason we need to use square brackets is to tell the agent control that there is more than one possible word or phrase to access the command. So the command will be accessed when the user says "Advanced Character Options" OR when the user says "Advanced". Please note that in order for the agent to listen for commands, the user needs to press the listening hotkey. You can change this hotkey in the properties window that our command loads.

Page 2 of 6

Comment and Contribute


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



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel