Make your own free website on Tripod.com


JavaScript Codes for Hello World Java Script

<Object ID="AgentControl" Width=0 Height=0
ClassID="CLSID:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F"
CodeBase="#VERSION=2,0,0,0">
</Object>

<Object ID="L&HTruVoice" Width=0 Height=0
ClassID="CLSID:B8F2846E-CE36-11D0-AC83-00C04FD97575"
CodeBase="#VERSION=6,0,0,0">
</Object>

<Script Language="JavaScript">
<!--

// * Character Objects
var Merlin;

// * Variables
var UsedChars;
var MerlinID;
var MerlinACS;
var MerlinLoaded;
var LoadReq;
var HideReq;

// * Initialize
UsedChars = "Merlin";

// * Merlin
MerlinID = "Merlin";
MerlinACS = "merlin.acs";
MerlinLoaded = false;


Window_OnLoad();

function Window_OnLoad() {
// Purpose: Runs automatically when page is loaded

// * INSERT ANY NON-AGENT RELATED SCRIPTING HERE

AgentControl.Connected = true;

MerlinLoaded = LoadLocalAgent(MerlinID, MerlinACS);

if (MerlinLoaded) {
SetCharObj();
}
CheckLoadStatus();
}

function LoadLocalAgent(CharID, CharACS) {
// Purpose: Attempts to load the specified character
// Returns: true if successful, false if not

AgentControl.RaiseRequestErrors = false;
LoadReq = AgentControl.Characters.Load(CharID, CharACS);
AgentControl.RaiseRequestErrors = true;

if (LoadReq.Status != 1) {
return(true);
}
return(false);
}

function SetCharObj() {
// Purpose: Sets the character reference and TTS Language ID

Merlin = AgentControl.Characters.Character(MerlinID);
Merlin.LanguageID = 0x409;
}

function CheckLoadStatus() {
// Purpose: Determines if required characters have been loaded.
// If not, issue request to load next character
// else run the AgentIntro routine

if (!MerlinLoaded) {
LoadError();
return(false);
}

window.status = "";
AgentIntro();
return(true);
}

function LoadError() {
var strMsg;
window.status = "";
strMsg = "Error Loading Character: " + MerlinID + "\n";
strMsg = strMsg + "This Microsoft Agent Script requires the character(s):\n";
strMsg = strMsg + UsedChars;
alert(strMsg);
}
function InitAgentCommands() {
// Purpose: Initialize the Commands menu

Merlin.Commands.RemoveAll();
Merlin.Commands.Caption = "My Menu Name";
Merlin.Commands.Add("ACO", "Advanced Character Options", "Advanced Character Options");
}

function AgentIntro() {
InitAgentCommands();

// *** BEGIN MASH USER SCRIPT ***

Merlin.Show();
Merlin.Speak("Hello World!");


// *** END MASH USER SCRIPT ***
}
//-->
</Script>

<Script Language="JavaScript" For="AgentControl" Event="RequestComplete(RequestObject)">
<!--//
// Purpose: Take action on completion or failure of requests

//-->
</Script>

<Script Language="JavaScript" For="AgentControl" Event="Command(UserInput)">
<!--//
// Purpose: Determine Command that was selected either by menu or voice
// and run the applicable Command Script
var BadConfidence;
BadConfidence = 10;

if (UserInput.Confidence <= -40)
{
// Bad Recognition
}
else if ((UserInput.Alt1Name != "") && (Math.abs(Math.abs(UserInput.Alt1Confidence) - Math.abs(UserInput.Confidence)) < BadConfidence))
{
// Bad Confidence - too close to another command
}
else if ((UserInput.Alt2Name != "") && (Math.abs(Math.abs(UserInput.Alt1Confidence) - Math.abs(UserInput.Confidence)) < BadConfidence))
{
// Bad Confidence - too close to another command
}
else
{
// High Confidence
// *** BEGIN MASH USER COMMANDS ***
switch(UserInput.Name) {
case "ACO" :
AgentControl.PropertySheet.Visible = true;
break;
}
// *** END MASH USER COMMANDS ***
}
//-->
</Script>


<Script Language="JavaScript" For="AgentControl" Event="Bookmark(BookmarkID)">
<!--//
//-->
</Script>


<Script Language="JavaScript" For="AgentControl" Event="Click(CharacterID, Button, Shift, X, Y)">
<!--
// Insert Click Event Code Here
-->
</Script>

<Script Language="JavaScript" For="AgentControl" Event="DblClick(CharacterID, Button, Shift, X, Y)">
<!--
// Purpose: Stop and Hide all characters on double-click

Merlin.StopAll();
if (!Merlin.HasOtherClients) {
if (Merlin.Visible) {
HideReq = Merlin.Hide();
}
else {
AgentControl.Characters.Character.Unload(MerlinID);
}
}
->
</Script>