|
Tom L. Hall President |
|
Issue 10
Sept 15, 2007 |
This Newsletter comes quickly after Issue 9 but someone trying to do a lesson in my Actions Editor, Simulations, ActiveX, and HTTP Post book has stimulated me to do some work with Microsoft Agents in ToolBook this week.
In this Issue:
For
several versions of my Actions Editor book, I have covered how to make the
Microsoft Agents work in Native ToolBook applications as an example of ActiveX
in ToolBook. For those of you not familiar with this, the Microsoft Agents are
Merlin, Peedy, Genie, and Robby (a magician, a bird, a genie, and a robot) and
are characters that can be animated using a defined group of commands as well
as speak text. There is a setup that is
needed but once you install what is needed, you are all set. In the book, I have an extensive set of
lessons on making this work but it requires a lot of OpenScript and is a bit
painful. Likewise, a long time back, I
used a small routine provided by Cecil Cheah (so where is he these days for
those of you who remember?) that used a Display URL action to call JavaScript
functions to then have an HTML Product where the Agents would work. This was in the days prior to us having the
ability to add JavaScript to ToolBook and then use the Actions Editor to execute
the functions we might find in the js file.
Back to the “old” way. It was a bit painful to also have the ability to
use the Agents in a ToolBook application to be converted to HTML. This method also forced me to provide lessons
to show the developer how to insert the code needed to hook the HTML product up
to the old JavaScript file. Likewise, it was necessary to get the ID of the
control that has been added to the page to make this work and then do an edit
to the JavaScript file. The last part is
still needed but the rest if fairly painless. So much so, that I have an
interest in this again and would like to use it as a good example of how we can
easily incorporate JavaScript into our ToolBook applications that we deploy to
the Web.
For convenience, I have updated a Web page to provide links to where you
can download and install the components needed to make this work. Just follow
the instructions on this page and you will be all set.
http://tcc-pub.com/agents/agents.htm
Basically,
you install the core components, one or more characters, the text to speech
engine, and perhaps an additional component to make sure that the text to
speech engine works. Likewise, there are
lots more characters out there and it would be easy to use them once you get
going with one of the Microsoft Four.

After you have installed what is needed, you will need to download a
sample file, just to make sure you get going properly. It will still be up to
you to make the post-Export edit that is needed.













Before we do anything else, let’s look at the agents3.js file that you downloaded and saved previously. The top part of this code will not be touched
by you except for a simple substitution of a number once we know what the ID of
the agent control is. The main thing is to look at the tbfunctions. This is how we designate a function to be identified
by ToolBook:
function tbfunction_WinLoad()
{
document.sys126.Connected = true;
MerlinLoaded = LoadLocalAgent(MerlinID, MerlinACS);
if (MerlinLoaded) {
SetCharObj();
}
CheckLoadStatus();
}
function
tbfunction_showAgent(){
InitAgentCommands();
Merlin.MoveTo(0, 0);
Merlin.Show();
Merlin.Speak("Hello, my name is Merlin.");
}
function
tbfunction_moveToAgent(){
GetScreenPositions();
InitAgentCommands();
Merlin.Show();
Merlin.MoveTo(MerlinCenterX , MerlinCenterY );
Merlin.Speak("Did you see me move?");
}
function
tbfunction_ReadInput(readme){
var texttoread=readme
GetScreenPositions();
InitAgentCommands();
Merlin.Show();
Merlin.Speak(texttoread);
}
function
tbfunction_agentdomagic() {
InitAgentCommands();
Merlin.Show();
Merlin.Play("DoMagic2");
}
function
tbfunction_agenthide() {
InitAgentCommands();
Merlin.Hide();
}
The first function is the one we call on loading the page. The others are the ones called by the on
click events of the buttons. Hopefully you
can easily see what you can do to have Merlin speak more text. Take a look at
the Merlin.Speak(“Hello, my name is Merlin.”) line.
The Do Magic button calls the function that has a Merlin.Play(“DoMagic2”)
line. More on where this comes (the DoMagic2)
from later.
As shown above, the button to have Merlin get the text from the input
field and speak it is a bit more complicated. Here we pass out whatever is
typed as a parameter named readme, set a variable equal to that, and
then have Merlin speak the contents of the variable (texttoRead). Actually, pretty simple isn’t it? As suggested by the person who started me
down this road by asking about the original lesson in the book, you could have
the student type something and then Merlin would speak it. Likewise, you could
have Merlin read the text of a Question and the answers to choose from. There are all sorts of possibilities
here. I personally like the idea of
passing the text to read as a parameter each time as this avoids having to have
a whole bunch of functions that are hardcoded to speak various strings of
text. You would still need to write
other functions for the different Play actions. If you want Merlin to appear on other pages,
a better technique would be to put the control on a common background and then
get the ID as described below form the JavaScript file for the background,
often either b0.js or b1.js. The main thing is to come up with a way where
you only load the Agent once for the whole book and I suggest this be the first
time you need the Agent on a page. This is critical to avoid errors when
returning to a page with the Agent.
Once you get going, you have to find out what each character can do and
this is a table of the Play actions I came across back when I wrote the
lessons I first did. In addition to
these Play actions, I needed to know about Show, Hide, MoveTo,
and Speak. I got a lot of my
information from a MASH program that is used to generate scripts for
incorporation directly into Web Pages. A
link to this is on the http://tcc-pub.com/agents/agents.htm
page.
|
Acknowledge Alert Announce Blink Confused Congratulate Congratulate_2 Decline DoMagic1 DoMagic2 DontRecognize Explain GestureDown GestureLeft GestureRight GestureUp GetAttention GetAttentionReturn Greet |
Hearing_1 Hearing_2 Hearing_3 Hearing_4 Hide Idle1_1 Idle1_2 Idle1_3 Idle1_4 Idle2_1 Idle2_2 Idle3_1 Idle3_2 LookDown LookDownBlink LookDownReturn LookLeft LookLeftBlink LookLeftReturn |
LookRight LookRightBlink LookRightReturn LookUp LookUpBlink LookUpReturn MoveDown MoveLeft MoveRight MoveUp Pleased Process Processing Read ReadContinued ReadReturn RestPose Sad |
Search Searching StartListening StopListening Suggest Surprised Think Thinking Uncertain Wave Write WriteContinued WriteReturn Writing |
Now, there is one final, very important task. We have to make an edit to
the Javascript file, but before we do, we need to know something.
p5.o0=new
_ah("p5.o0","sys114",true,true,false,"","",p5,"sys115","<span
id=\"sys114\"
style=\"height:33px;width:33px;visibility:inherit;z-index:32768;position:absolute;left:689px;top:427px;\"><object
classid=\"clsid:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F\"
id=\"sys115\" width=\"100%\"
height=\"100%\"><param name=\"mercury_id\"
value=\"p5.o0\"><param name=\"Connected\"
value=\"false\"><param name=\"RaiseRequestErrors\"
value=\"true\"></object></span>");
Note: It has come to my attention as
one or more of the first readers of this Newsletter try this, issues are coming
up and it’s worthy to discuss exactly what the student will encounter and be
reminded that it works only with IE.
First,
there likely will be an ActiveX message such as this:

I found
that click X and closing this message allowed the Agent to work even though the
message said it has been blocked. This
information bar can be turned off but it really is not recommended. Since this
only happens once, I would suggest that you just inform your students that they
will get this message but to ignore it.
A more
significant issue is the voice not being heard and I have to be honest and say
this first happened to me. I had
installed the core components, the agent, and the L&H TrueVoice speech
engine but only saw the bubble with the words with no sound. I went back and
installed the SAPI 4 component and it worked.
To make sure your student machines or end-user machines can handle this,
I would provide a link to a site like this:
http://chemware.co.nz/AgentSupport.htm
or create
your own Setup page where you tell the end-user what is needed if this does not
work. It is likely that most of the components needed will be there already but
this is an important note found on the above site:
Windows
2000 includes Microsoft TTS (synthetic speech engine) and SAPI 4 runtime. The SAPI 4
is needed to run TTS engines other than TruVoice.
Click here to see this
work.
TCC Publishing, Inc
Internet Address: tomhall1@tcc-pub.com
Phone:
252-758-4590
Fax:
252-758-4590