[從 Windows 7 開始,Microsoft Agent 已被取代,而且在後續版本的 Windows 中可能無法使用。]
伺服器也會公開 Characters 集合中每個字元的方法。 支援下列方法:
若要使用 方法,請參考集合中的字元。 在 VBScript 和 Visual Basic 中,您可以藉由指定字元的識別碼來執行此動作:
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>