Character 对象方法

[Microsoft 代理从 Windows 7 开始已弃用,可能在后续版本的 Windows 中不可用。]

服务器还公开 Characters 集合中每个字符的方法。 支持以下方法:

若要使用 方法,请引用 集合中的 字符。 在 VBScript 和 Visual Basic 中,可以通过指定字符的 ID 来执行此操作:

   Sub FormLoad

   'Load the genie character into the Characters collection
   Agent1.Characters.Load "Genie", "Genie.acs"

   'Display the character
   Agent1.Characters("Genie").Show
   Agent1.Characters("Genie").Play "Greet"
   Agent1.Characters("Genie").Speak "Hello. "

   End Sub

若要简化代码的语法,可以定义对象变量并将其设置为引用 Characters 集合中的字符对象;然后,可以使用变量引用字符的方法或属性。 以下示例演示如何使用 Visual Basic Set 语句执行此操作:

   'Define a global object variable
   Dim Genie as Object

   Sub FormLoad

   'Load the genie character into the Characters collection
   Agent1.Characters.Load "Genie", " Genie.acs"

   'Create a reference to the character
   Set Genie = Agent1.Characters("Genie")

   'Display the character
   Genie.Show

   'Get the Restpose animation
   Genie.Get "animation", "RestPose"

   'Make the character say Hello
   Genie.Speak "Hello."

   End Sub

在 Visual Basic 5.0 中,还可以通过将变量声明为 Character对象来创建引用:

   Dim Genie as IAgentCtlCharacterEx

   Sub FormLoad

   'Load the genie character into the Characters collection
   Agent1.Characters.Load "Genie", "Genie.acs"

   'Create a reference to the character
   Set Genie = Agent1.Characters("Genie")

   'Display the character
   Genie.Show

   End Sub

声明 IAgentCtlCharacterEx 类型的对象可以提前绑定对象,从而提高性能。

在 VBScript 中,不能将引用声明为特定类型。 但是,只需声明变量引用:

<SCRIPT LANGUAGE = "VBSCRIPT">
<!—--

   Dim Genie
   
   Sub window_OnLoad
   
   'Load the character
   AgentCtl.Characters.Load "Genie", "https://agent.microsoft.com/characters/v2/genie/genie.acf"

   'Create an object reference to the character in the collection
   set Genie= AgentCtl.Characters ("Genie")

   'Get the Showing state animation
   Genie.Get "state", "Showing"

   'Display the character
   Genie.Show

   End Sub

-->
   </SCRIPT>

某些编程语言不支持集合。 但是,可以使用 Character 方法访问 Character 对象的方法:

   agent.Characters.Character("CharacterID").method

此外,还可以创建对 Character 对象的引用,使脚本代码更易于遵循:

<SCRIPT LANGUAGE="JScript" FOR="window" EVENT="onLoad()">
<!--
   
   //Load the character's data
   AgentCtl.Characters.Load ("Genie", _
      "https://agent.microsoft.com/characters/v2/genie/genie.acf");   

   //Create a reference to this object
   Genie = AgentCtl.Characters.Character("Genie");
   
   //Get the Showing state animation
   Genie.Get("state", "Showing");

   //Display the character
   Genie.Show();

-->
</SCRIPT>