Condividi tramite


Metodi dell'oggetto Character

[Microsoft Agent è deprecato a partire da Windows 7 e potrebbe non essere disponibile nelle versioni successive di Windows.]

Il server espone anche i metodi per ogni carattere in un insieme Character . Sono supportati i metodi seguenti:

Per usare un metodo, fare riferimento al carattere nell'insieme. In VBScript e Visual Basic, si specifica l'ID per un carattere:

   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

Per semplificare la sintassi del codice, è possibile definire una variabile oggetto e impostarla per fare riferimento a un oggetto carattere nell'insieme Characters ; è quindi possibile usare la variabile per fare riferimento a metodi o proprietà del carattere. Nell'esempio seguente viene illustrato come eseguire questa operazione usando l'istruzione 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

In Visual Basic 5.0 è anche possibile creare il riferimento dichiarando la variabile come oggetto 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

Dichiarare l'oggetto di tipo IAgentCtlCharacterEx abilita l'associazione anticipata sull'oggetto, che comporta prestazioni migliori.

In VBScript non è possibile dichiarare un riferimento come tipo specifico. Tuttavia, è possibile dichiarare semplicemente il riferimento alla variabile:

<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>

Alcuni linguaggi di programmazione non supportano le raccolte. È tuttavia possibile accedere ai metodi di un oggetto Character con il metodo Character :

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

È anche possibile creare un riferimento all'oggetto Character per semplificare il codice dello script:

<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>