Script set to test NPC control

40 views
Skip to first unread message

Morris Ford

unread,
Mar 11, 2010, 8:04:39 PM3/11/10
to Open Wonderland Scripting
This is a set of scripts that is used to test the NPC interface. They
are javascript scripts. The exact same functionality could be
implemented in other languages as well or a mix of languages could be
used.

The mouse events need a little bit of explanation:

mouse1 - left mouse button
mouse1s - left mouse button + shift
mouse1c - left mouse button + control
mouse2 - middle mouse button

and the other two scripts

startup - this script executes on startup of the module. This is
ordinarily when the client starts.
ice - executes when the module receives an intercell event that
contains a code that the module has been instructed to listen for

The startup script instructs the module to listen to intercell
messages and to react to messages with code 300 by calling the ice
script. The ice script looks at the payload in the ice message and
decides what action to take. The calls to MyClass.executeAction() are
what calls to the module command interface look like. The four mouse
event scripts send the ice messages from '01' to '04'. If I didn't
make any typos typing this in, that set of scripts should show the
avatar walking and changing appearance. The ice script performs its
actions inside a new thread. This was not necessary since the module
commands each are executed in their own thread but I thought it would
be instructive. Using a structure like this would be important in a
script that is free running once executed.

startup.js

// startup script for NPC test
print("Hello from NPC test startup script\r\n");
MyClass.watchMessage(300);


ice.js

// intercell event script for NPC test
print("Enter ice.js script\r\n");
var v = new java.lang.Runnable()
{
run: function()
{
if(ICEEventMessage == '01')
{
print("ice start translate 1\r\n");
MyClass.executeAction("move", 1.0, 0.0, 1.0);
}
if(ICEEventMessage == '02')
{
print("ice start translate 2\r\n");
MyClass.executeAction("move", 10.0, 0.0, 10.0);
}
if(ICEEventMessage == '03')
{
print("ice start set avatar female\r\n");
MyClass.executeAction("selectAvatar", "assets/configurations/
FemaleD_AZ_00_bin.xml");
}
if(ICEEventMessage == '04')
{
print("ice start set avatar male\r\n");
MyClass.executeAction("selectAvatar", "assets/configurations/
MaleD_CA_01_bin.xml");
}
}
}

t = new java.lang.Thread(v);
i.start();


mouse1.js

// mouse1.js event script for NPC test
print("Enter mouse1.js script\r\n");
MyClass.postMessageEvent("01", 300);

mouse1s.js

// mouse1s.js event script for NPC test
print("Enter mouse1s.js script\r\n");
MyClass.postMessageEvent("02", 300);

mouse1c.js

// mouse1c.js event script for NPC test
print("Enter mouse1c.js script\r\n");
MyClass.postMessageEvent("03", 300);

mouse2.js

// mouse2.js event script for NPC test
print("Enter mouse2.js script\r\n");
MyClass.postMessageEvent("04", 300);

Morris Ford

unread,
Mar 12, 2010, 8:38:13 AM3/12/10
to Open Wonderland Scripting
A little bit more information is required to make this work.

The startup and ice scripts must be attached to a Scripting NPC module
and the mouse scripts attached to another module that will accept
mouse clicks.

To make this work:

Checkout a scripting component and a scripting npc component from the
module warehouse.

Install both in your system using the web admin interface -> manage
modules.

In the client insert an npc module.

Since the npc module will not bring up the properties window on a
mouse click, click on some object in world and bring up the properties
window. Then go through the modules until you find the npc module.
Change the cell name to the name you want to use for the npc (no
spaces please).

Select (or insert) a module that is composed of just a model. Bring up
the properties for that module and change the name to a name for the
module. The name must be different than the npc name.

Assuming that you have full access to the server computer that is
running OWL and that you are using preview3, create the following
paths in the filesystem:
.wonderland-server/0.5-preview3/run/content/scripts/{npc-name} - npc-
name is the name you gave to the NPC.
.wonderland-server/0.5-preview3/run/content/scripts/{module-name} -
module-name is the name you gave to the module.

The scripts/names part of the path will be all that you actually have
to create.

Place the npc scripts (startup and ice) in the new npc directory.
Place the module scripts (mouse's) in the new module directory.

Create a new startup script in the module directory with contents
similar to this:

// startup script
print("Startup script\r\n");

This script is being created to give the module a script to run on
startup.

Restart the client.

You should see logging in the java console showing the two modules
starting up and running their start up scripts. If you see java
exceptions there is probably a mistake in the naming or in the paths
created.

Now you can click on the module you created with one of the mouse
button and key combinations to test the NPC.

NOTE:
I realize that is a lot of fooling around to get the scripts in place.
There are actually a couple of easier ways to go about this but doing
it this way at the start will help with understanding where the
scripts live and the relationship between module names and scripts.

Good luck
Morris

Josmas Flores

unread,
Mar 20, 2010, 7:01:17 PM3/20/10
to Open Wonderland Scripting
Hi Morris,

thanks for your instructions! I have been playing with it for a while
but cannot get it to work well.

I can place the NPC guy and it is reading the startup script for that
and showing the print statement in console. I can also make it move
through the controls in (Edit --> NPC 2 controls...) but I am having
trouble with the module that will receive the clicks.

When you say "Select (or insert) a module that is composed of just a
model", would it be enough to drag inside the world a .kmz file?
I have tried that, and also tried the longer path (insert --> model --
> load model --> save as module --> deploy to server --> ok) but the
startup line for that other module do not appear in console, and it
does not respond to the clicks.
Any idea about what I am missing?


Oh, by the way, I don't know if this is specific to mac, or 0.5-dev,
but i had to place the scripts into

.wonderland-server/0.5-xxx/run/content/users/{username}/scripts/{npc-
name}

so i had to add /users/{username} to it or it could not find them.

Cheers,
Jos

Morris Ford

unread,
Mar 20, 2010, 7:10:46 PM3/20/10
to open-wonderl...@googlegroups.com
You will need to change the name of the simple model you insert into the world and then create script paths for that name. You then have to add the scripting component to that model from the properties screen. That is done by clicking the + sign in the properties window and then selecting the ScriptingComponent. At that point you should see the logging showing that module's startup stuff.

The paths you needed are due to using the trunk instead of preview3. That is ok since you figured out the difference.

If you have other problems, let me know.
Morris

To unsubscribe from this group, send email to open-wonderland-scripting+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Josmas Flores

unread,
Mar 20, 2010, 8:33:47 PM3/20/10
to open-wonderl...@googlegroups.com
(Sorry if you get this twice!!! is there any filtering going on??? cannot see my previous message... anyway)

Thanks Morris,

that was spot on! Having a few exceptions now but will have to wait till tomorrow. At least the javascript files are being loaded now! :)

cheers,
Jos

Nicole Yankelovich

unread,
Mar 20, 2010, 10:41:29 PM3/20/10
to open-wonderl...@googlegroups.com
Jos,

The forum is not moderated in any way, but occasionally some messages do get marked as spam and someone has to go in and say that they are not spam, causing a delay in posting. What causes this to happen is a complete mystery. I haven't spotted any pattern or been able to figure out what is triggering the spam filter. I suppose it's also possible that some messages are getting filtered out all together, but I'm not sure.

Nicole.

Josmas Flores

unread,
Mar 21, 2010, 5:43:44 AM3/21/10
to open-wonderl...@googlegroups.com
thanks Nicole, I guess it's just a matter to send it again if that happens so not big a deal! :)

Josmas Flores

unread,
Mar 21, 2010, 6:49:38 AM3/21/10
to open-wonderl...@googlegroups.com
Hi again guys,

there seems to be something not quite right in the sources for the scripting module in trunk. I am missing the class org.jdesktop.wonderland.modules.scriptingComponent.common.ScriptingComponentCellCreateMessage.
Not sure if it's part of a refactoring and it has been deleted on purpose, but checked preview3 and the class exists there. Quick hack --> copying the class into my local copy of trunk gets rid of that particular compilation issue but not sure it will fix it. Having some other issues to compile right now but that's probably my own environment, so will have to figure that out by myself :)

ta!
Jos

Josmas Flores

unread,
Mar 21, 2010, 8:00:20 PM3/21/10
to open-wonderl...@googlegroups.com
And it's me again, I'm missing a whole load of classes in here, not sure what's going on but compared to preview3 I can see a ton of changes. The only class that I cannot compile now is:
ScriptingComponent.java

some of the dependencies that are not met:
ScriptingActionClass
ControllerInterface
truck
fixedWing
ScriptingRunnable

It loos a bit like experimental code (@ExperimentalAPI) so maybe I should start looking at other modules instead? :S

cheers,
Jos

Morris Ford

unread,
Mar 21, 2010, 8:26:14 PM3/21/10
to open-wonderl...@googlegroups.com
Are you using source? If so, it is not up to date. You should be using the binary modules from the module repository.

Josmas Flores

unread,
Mar 22, 2010, 7:58:13 AM3/22/10
to open-wonderl...@googlegroups.com
Hey Morris, I am using source cause I couldn't get the module from the warehouse to work. 
I suppose that is because I installed the warehouse module onto a trunk server. I guess preview3+warehouse is the combination that works. Will try that when I get home.

thanks,
Jos

Morris Ford

unread,
Mar 22, 2010, 8:54:19 AM3/22/10
to open-wonderl...@googlegroups.com
There will be a newer version soon so if you cannot get the binary one to work with preview3 just post back and I'll get a newer one set up. I have added a lot of things and I am working on testing now.

Josmas Flores

unread,
Mar 22, 2010, 9:35:13 AM3/22/10
to open-wonderl...@googlegroups.com
thanks Morris, if you need a hand with the testing I'll be happy to help.

Josmas Flores

unread,
Mar 20, 2010, 8:01:38 PM3/20/10
to Open Wonderland Scripting
Hey Morris, thanks again, spot on! was not adding the scripting
capability to the second module.

I'm getting some exceptions now but I'll try to track them down
tomorrow, bed time over here already!
Will build the scripting module from the trunk and see if it's
anything related to using 0.5-dev and the module from the warehouse.

cheers!
Jos

On Mar 20, 11:10 pm, Morris Ford <morrishf...@gmail.com> wrote:
> You will need to change the name of the simple model you insert into the
> world and then create script paths for that name. You then have to add the
> scripting component to that model from the properties screen. That is done
> by clicking the + sign in the properties window and then selecting the
> ScriptingComponent. At that point you should see the logging showing that
> module's startup stuff.
>
> The paths you needed are due to using the trunk instead of preview3. That is
> ok since you figured out the difference.
>
> If you have other problems, let me know.
> Morris
>

Morris Ford

unread,
Mar 28, 2010, 2:02:45 PM3/28/10
to Open Wonderland Scripting
I found a couple of little issues with the ice script. Here is the
script:

ice.js
// intercell event script for NPC test
print("Enter ice.js script\r\n");
var v = new java.lang.Runnable()
{
run: function()
{
if(ICEEventMessage == '01')
{
print("ice start translate 1\r\n");
MyClass.executeAction("move", 1.0, 0.0, 1.0);
}
if(ICEEventMessage == '02')
{
print("ice start translate 2\r\n");
MyClass.executeAction("move", 10.0, 0.0, 10.0);
}
if(ICEEventMessage == '03')
{
print("ice start set avatar female\r\n");
MyClass.executeAction("selectAvatar", "assets/configurations/
FemaleD_AZ_00_bin.xml");
}
if(ICEEventMessage == '04')
{
print("ice start set avatar male\r\n");
MyClass.executeAction("selectAvatar", "assets/configurations/
MaleD_CA_01_bin.xml");
}
}
}
t = new java.lang.Thread(v);

t.start();

There were three problems. The last line should have been t.start();
Also the two long lines that are split here (the change avatar
commands) should not be split in the script itself.
Morris

oksamyt

unread,
Apr 20, 2010, 2:36:27 PM4/20/10
to Open Wonderland Scripting
Hello Morris,

I have used your scripts to test the npc control, but I have created
only mouse1.js for the model (all the other scripts have been created
as needed + I have created an empty ice.js in the model directory in
order not to get a FileNotFound exception). When I click on the model,
the npc starts moving around in various ways and seems to never stop.
I suggested the code makes it move to a point (1.0, 0.0, 1.0). Where
can I read about this executeAction() function?

My revision is 4407.

Thanks for attention.

Oxana Zhuravlyova


--
Subscription settings: http://groups.google.com/group/open-wonderland-scripting/subscribe?hl=en

Morris Ford

unread,
Apr 20, 2010, 6:24:06 PM4/20/10
to open-wonderl...@googlegroups.com
Try a location of 1, 0.5, 1 or 1,1,1. The NPC move routine sometimes misses the target spot because that y axis point is too low.

oksamyt

unread,
Apr 21, 2010, 1:34:02 PM4/21/10
to Open Wonderland Scripting
Thanks for the reply! It turned out the npc eventually made it to the
location, but due to the fact that it was a little bit above 0
originally, it took it a while to descend :-)

I guess I'll have to check the source code for the available functions
in npc scripting.

On Apr 21, 1:24 am, Morris Ford <morrishf...@gmail.com> wrote:
> Try a location of 1, 0.5, 1 or 1,1,1. The NPC move routine sometimes misses
> the target spot because that y axis point is too low.
>

oksamyt

unread,
Apr 22, 2010, 10:56:41 AM4/22/10
to Open Wonderland Scripting
Erm... Can I get the source anywhere? Or are 'move' and 'selectAvatar'
all the actions the npc can execute?

On Apr 21, 8:34 pm, oksamyt <oksa...@gmail.com> wrote:
> Thanks for the reply! It turned out the npc eventually made it to the
> location, but due to the fact that it was a little bit above 0
> originally, it took it a while to descend :-)
>
> I guess I'll have to check the source code for the available functions
> in npc scripting.
>


Josmas Flores

unread,
Apr 22, 2010, 12:29:41 PM4/22/10
to open-wonderl...@googlegroups.com
Hi there, the source code for Morris' scripting tool is in the unstable (i think) folder of the modules source tree. More info here:

cheers,
Jos

oksamyt

unread,
Apr 22, 2010, 12:40:49 PM4/22/10
to Open Wonderland Scripting
I could not find the 'scriptingNpc' in modules source, that's why I
decided to ask here. Anyway, I guess the npc can't do any other
actions, so I don't need any extra documentation. Thanks for the
response!

On Apr 22, 7:29 pm, Josmas Flores <josmasflo...@gmail.com> wrote:
> Hi there, the source code for Morris' scripting tool is in the unstable (i
> think) folder of the modules source tree. More info here:http://code.google.com/p/openwonderland/wiki/DownloadBuildModules05
>
> <http://code.google.com/p/openwonderland/wiki/DownloadBuildModules05>cheers,
> Jos

Morris Ford

unread,
Apr 23, 2010, 6:55:48 AM4/23/10
to open-wonderl...@googlegroups.com
Here is the command stack from the NPC:

            sac.insertCmdMap("testit", testitRun);
            sac.insertCmdMap("move", moveRun);
            sac.insertCmdMap("selectAvatar", avatarSelectAvatarRun);
            sac.insertCmdMap("startForward", avatarStartForwardRun);
            sac.insertCmdMap("stopForward", avatarStopForwardRun);
            sac.insertCmdMap("startBack", avatarStartBackRun);
            sac.insertCmdMap("stopBack", avatarStopBackRun);
            sac.insertCmdMap("startLeft", avatarStartLeftRun);
            sac.insertCmdMap("stopLeft", avatarStopLeftRun);
            sac.insertCmdMap("startRight", avatarStartRightRun);
            sac.insertCmdMap("stopRight", avatarStopRightRun);
            sac.insertCmdMap("startUp", avatarStartUpRun);
            sac.insertCmdMap("stopUp", avatarStopUpRun);
            sac.insertCmdMap("startDown", avatarStartDownRun);
            sac.insertCmdMap("stopDown", avatarStopDownRun);
            sac.insertCmdMap("dumpAnimations", avatarDumpAnimationsRun);
            sac.insertCmdMap("runAnimation", avatarRunAnimationRun);
            sac.insertCmdMap("stopAnimation", avatarStopAnimationRun);

I have not had time to test a lot of the commands lately. Most are reasonably self explanatory. The dumpAnimations will dump out a list of the animations for the avatar. RunAnimation and StopAnimation take the animation name from that list as a parameter. From a script it would look like MyClass.executeAction("runAnimation", "wave");

Nussbaum-Jones, Nina

unread,
Apr 23, 2010, 11:58:48 AM4/23/10
to open-wonderl...@googlegroups.com

http://java.sun.com/developer/technicalArticles/scripting/javafx/javafx_and_java/

 

This gives the description of JSR 223/fx.  Is this the info that was required to integrate into your scripting module?

Morris Ford

unread,
Apr 23, 2010, 12:04:27 PM4/23/10
to open-wonderl...@googlegroups.com
No. This looks like a description of how to interface directly between java and javafx.The needed information is involved with how javafx acts across the java->jsr223->script boundary.

oksamyt

unread,
Apr 26, 2010, 2:07:20 PM4/26/10
to Open Wonderland Scripting
Thank you very much for the pointers! However, I tried several avatars
(the default one and two others), dumped the animations list, tried to
execute some from the list and every time got this exception:

ScriptingComponent - enter executeAction - String param
Exception in thread "Thread-781"
org.mozilla.javascript.WrappedException: Wrapped
java.lang.NullPointerException (<Unknown Source>#11)
at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:
1693)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:157)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:
201)
at org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:
74)
at org.mozilla.javascript.gen.c16._c1(<Unknown Source>:11)
at org.mozilla.javascript.gen.c16.call(<Unknown Source>)
at
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:
337)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:
2755)
at org.mozilla.javascript.gen.c16.call(<Unknown Source>)
at org.mozilla.javascript.Context.call(Context.java:499)
at org.mozilla.javascript.JavaAdapter.callMethod(JavaAdapter.java:
489)
at adapter1.run(<adapter>)
at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.NullPointerException
at
org.jdesktop.wonderland.modules.avatarbase.client.jme.cellrenderer.WlAvatarContext.setMiscAnimation(WlAvatarContext.java:
71)
at
org.jdesktop.wonderland.modules.avatarbase.client.jme.cellrenderer.WlAvatarContext.playMiscAnimation(WlAvatarContext.java:
56)
at
org.jdesktop.wonderland.modules.avatarbase.client.jme.cellrenderer.WlAvatarCharacter.playAnimation(WlAvatarCharacter.java:
103)
at
org.jdesktop.wonderland.modules.scriptingNpc.client.cell.NpcCell.avatarRunAnimation(NpcCell.java:
257)
at org.jdesktop.wonderland.modules.scriptingNpc.client.cell.NpcCell
$5.run(NpcCell.java:265)
at
org.jdesktop.wonderland.modules.scriptingComponent.client.ScriptingComponent.executeAction(ScriptingComponent.java:
422)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:142)
... 11 more

Do I have to initialize anything before calling executeAction()?

Bay Nicdao

unread,
Jun 10, 2010, 12:04:08 AM6/10/10
to Open Wonderland Scripting
Hi,

I was able to make gesture animations to work.
I seems that the MyClass.executeAction() method requires 3 parameters
to execute the animation. That 3rd parameter should be of integer
type. See below my sample animation script sequence, hope this helps:

if(ICEEventMessage == '00')
{
print("Doing Canned Animation\r\n");
MyClass.executeAction("startRight");
MyClass.mySleep(8000);
MyClass.executeAction("stopRight");
MyClass.executeAction("dumpAnimations");
MyClass.mySleep(2000);
MyClass.executeAction("runAnimation","Male_Wave",1);
MyClass.mySleep(4000);
MyClass.executeAction("runAnimation","Male_PublicSpeaking",1);
MyClass.mySleep(9000);
MyClass.executeAction("runAnimation","Male_Bow",1);
MyClass.mySleep(4000);
MyClass.executeAction("runAnimation","Male_TakeDamage",1);

oksamyt

unread,
Jun 11, 2010, 4:27:08 PM6/11/10
to Open Wonderland Scripting
Thanks a lot, it works for me too!
Reply all
Reply to author
Forward
0 new messages