Difference between revisions of "Bot Global"

From Virtual World Web Wiki
Jump to: navigation, search
(Documentation for the Bot Global class)
 
(Documentation for the Bot Global class)
Line 1: Line 1:
 +
The Bot JavaScript global object is available from server world scripts and provides methods for animating bots
 +
 
* This is a JavaScript visible object
 
* This is a JavaScript visible object
 
===Remarks <nowiki>[</nowiki>[{{fullurl:Bot Global Remarks|action=edit}} edit]<nowiki>]</nowiki>===
 
===Remarks <nowiki>[</nowiki>[{{fullurl:Bot Global Remarks|action=edit}} edit]<nowiki>]</nowiki>===
Line 5: Line 7:
 
===Methods===
 
===Methods===
 
:{{CSharp|ReturnType IsAvailable()}}
 
:{{CSharp|ReturnType IsAvailable()}}
 +
::
 +
::True if the HumanAvatars component is installed
  
 
:{{CSharp|ReturnType PlayAnimation(IDOMObjectExtended source, string animationName, bool looping)}}
 
:{{CSharp|ReturnType PlayAnimation(IDOMObjectExtended source, string animationName, bool looping)}}
 +
::
 +
::Same as above, but for bots in a room rather than player avatars
  
 
:{{CSharp|ReturnType StopAnimation(IDOMObjectExtended source, string animationName)}}
 
:{{CSharp|ReturnType StopAnimation(IDOMObjectExtended source, string animationName)}}
 +
::
 +
::Same as above, but for bots in a room rather than player avatars
  
 
__NOTOC____NOEDITSECTION__
 
__NOTOC____NOEDITSECTION__

Revision as of 00:45, 23 October 2016

The Bot JavaScript global object is available from server world scripts and provides methods for animating bots

  • This is a JavaScript visible object

Remarks [edit]

Here's a little example of the bot system in use. The script spawns a bot named "Mr. Botterson" at 5,0,5 and clothes it with object types for Legs, Torso, Hair and Feet. It then starts dancing. It creates a trigger volume around the bot as well. If you enter the trigger, the bot will send a chat message into the local chat channel telling you you can click on him. If you do, the bot will stop dancing and follow you around until you click on him again.

// Create a bot, named as requested
var botName = DOM.Self.Properties.GetString("BotName");
var avatar = Bot.Create("ham.creatures.male", botName, false); // initially invisible
 
// Cloth the avatar
avatar.Wear("Legs", "bfa290ba-0d97-11e2-8ef3-e0cb4e701b2c");
avatar.Wear("Torso", "5ae25c9e-0e5e-11e2-8ef3-e0cb4e701b2c");
avatar.Wear("Hair", "ef49dd5f-c0ec-11e3-a84a-00505692287c");
avatar.Wear("Feet", "02c5bf78-18b0-11e2-8ef3-e0cb4e701b2c");
 
// Copy an audio font from under our own DOM Tree onto the avatar
DOM.Self.QuerySelector("DOMAudioFont[Title='BotSounds']").Clone(avatar.Body);
 
// Spawn the avatar at the target
var spawn = avatar.Body.SpawnArea(1.0);
spawn.TargetID = DOM.Self.QuerySelector("DOMTarget[Title='Spawn']").ID;
spawn.Start();
 
// Start it dancing
avatar.StartAnimation("Dance", "PointVictor", true);
 
// Create a trigger volume for noticing an approaching player
var trigger = avatar.Body.CreateVolume({x:6.0, y:1.0, z:6.0});
 
// Set up a click handler to start and stop following
var follow = null;
avatar.Body.OnClick = function(part) {
    if (follow == null) {
        avatar.Say("I think I'll follow " + part.Name + " around for a while.");
        avatar.StopAnimation("Dance", "PointVictor");
        follow = avatar.Body.Follow(part.Controller);
        follow.Start();
    } else {
        avatar.Say("Ok I'll stop...");
        follow.Stop();
        avatar.StartAnimation("Dance", "PointVictor", true);
        follow = null;
    }
};
 
// Set up a volume trigger to handle a player approaching
trigger.OnEnter = function(part){
    if (follow == null){
        avatar.Body.AudioEvent("Whistle");
        avatar.Say("Hey " + part.Name + ", it's "+avatar.Title+"! Click on me!");
        var face = avatar.Body.FaceTarget(part.Controller, 360.0);
        face.Start();
    }
};

Methods

ReturnType IsAvailable()
True if the HumanAvatars component is installed
ReturnType PlayAnimation(IDOMObjectExtended source, string animationName, bool looping)
Same as above, but for bots in a room rather than player avatars
ReturnType StopAnimation(IDOMObjectExtended source, string animationName)
Same as above, but for bots in a room rather than player avatars