Script Context - Adobe ATMOSPHERE User Manual

Table of Contents

Advertisement

For Viewpoint objects and script-loaded scene groups, it is possible for the object to exist before all of its elements
(such as geometry) have been fully loaded. Attempting to use such elements prematurely will cause an error. (One
such example is using the object to create a physical model from geometry that has not loaded yet.) It is important,
therefore, to wait until the objects have fully loaded before proceeding further.
Whenever a script is told to run, and the script does not return within a specifi ed duration, the script will "time out",
that is be permanently stopped. Scripts are prevented from looping continuously in this way to avoid hanging the
system. This requires that scripts do not loop continuously waiting for an object to load. Instead a call-back is needed
in the script to check the status of objects. There are two possibilities: one is to defi ne a timestep function, called
back every frame and within which the "loaded" fl ag is tested until true; a second approach is to defi ne an "onLoad"
function, that will be called back once when the object fi nishes loading. In either case, the object must be added to the
list of objects which will receive callbacks via the "addAnimator" function.
i
Many of the Preset scripts included with Atmosphere initiate a timestep which tests to see if the target object is loaded
prior to performing any action on it. See the code in these scripts for an example of best practices on testing whether
something is loaded.

Script Context

JavaScripts attached to objects may be run in three different situations or "contexts". Atmosphere creates three global
variables to aid in this distinction:
this global variable will be "true" anytime that a script is not attached to an avatar in any manner (that
worldContext
is, not used by an AER fi le which is loaded as an avatar).
this global variable will be true for the owner of an avatar only. In other words, when a script is
localAvatarContext
attached to an AER fi le which is then loaded as an avatar, this variable will be true only for the person who is using the
AER fi le as their avatar.
this global variable will be true for your avatar script when it is being run on a remote users
remoteAvatarContext
computer.
This distinction allows an avatar owner to process events differently depending upon the context of the avatar. For
example, an avatar may contain animations which are triggered by buttons on the control panel. The avatar owner
may wish to only create the buttons on their local control panel, and not those of the remote users. In addition, these
global variables may also be used in conjunction with the chat.fi lter() method to send silent messages to their remote
avatar, triggering the animations on the remote user's computer.
241
ADOBE ATMOSPHERE
User Guide

Advertisement

Table of Contents
loading

Table of Contents