Table Of Contents

Previous topic

sandbox

Next topic

system.Class

This Page

system

Constructor

class system()

Methods

basicHttpGet(type, url, headers, callback)
Arguments:
  • type (String) – (GET or POST) are only two supported for now.
  • url (String) – or ip address.
  • headers (String) – formatted as a string (with rn’s ending each line)
  • callback (function) – to execute on success or failure (first arg of function is bool. If success, bool is true, if fail, bool is false). Success callbacks have a second arg that takes in an object with the following fields: respHeaders (string map). contentLength (number). status code (number). data (string).
canCreateEntity()
Returns:TRUE if the script is allowed to create a new entity on the current host, FALSE otherwise

Tells whether the script is allowed to create a new entity

canCreatePresence()
Returns:TRUE if the script is allowed to create a new presence for the entity, FALSE otherwise

Tells whether the script is allowed to create a new presence

canEval()
Returns:TRUE if eval() is invokable in the script
canImport()
Returns:TRUE if the script is allowed to import an emerson script using system.import, FALSE otherwise

Tells whether the script is allowed to import another emerson script

canProx()
Returns:TRUE if the script is allowed to register for proximity queries, FALSE otherwise

Tells whether the script is allowed to register for proximity queries

canRecvMessage()
Returns:TRUE if the script is allowed to receive a message, FALSE otherwise

Tells whether the script is allowed to register to receive messages

canSendMessage()
Returns:TRUE if the script is allowed to send a message, FALSE otherwise

Tells whether the script is allowed to send messages

changeSelf(toChangeTo)
Arguments:
  • toChangeTo (string) – The sporef of the presence that we want to change self to.
create_context()

Deprecated since version Use: createSandbox

create_entity()

Deprecated since version Use: createEntity

create_presence()

Deprecated since version Use: createPresence

createEntity(position, scriptOption, initFile, mesh, scale, solidAngle)
Arguments:
  • position (util.Vec3) – (eg. new util.Vec3(0,0,0);). Corresponds to position to place new entity in world.
  • scriptOption (String) – Script option to pass in. Almost always pass “js”
  • initFile (String) – Name of file to import code for new entity from.
  • mesh (String) – Mesh uri corresponding to mesh you want to use for this entity.
  • scale (Number) – Scale of new mesh. (Higher number means increase mesh’s size.)
  • solidAngle (Number) – Solid angle that entity’s new presence queries with.
Throws Exception:
 

Calling create_entity in a sandbox without the capabilities to create entities throws an exception.

Creates a new entity on the current entity host.

Deprecated since version Use: createEntityScript instead.

See also

system.canCreateEntity

createEntityFromPres(presence, script, arg, solidAngle, Mesh, scale)
Arguments:
  • presence – or visible.
  • pos. – Position of new entity’s first presence relative to first argument’s position
  • script – Can either be a string, which will be eval-ed on new entity as soon as it’s created or can be a non-closure capturing function that will be executed with next parameter as its argument.
  • arg – Object Passed as argument to script argument if script argument is a function.
  • solidAngle – Solid angle that entity’s new presence queries with.
  • Mesh (optional) – uri corresponding to mesh you want to use for this entity. If undefined, defaults to self’s mesh.
  • scale (optional) – Scale of new mesh. (Higher number means increase mesh’s size.) If undefined, default to self’s scale.

Creates a new entity based on the position and space of presence passed in.

createEntityScript(position, Script, Object, solidAngle, Mesh, scale, Space)
Arguments:
  • position – (eg. new util.Vec3(0,0,0);). Corresponds to position to place new entity in world.
  • Script – Can either be a string, which will be eval-ed on new entity as soon as it’s created or can be a non-closure capturing function that will be executed with next parameter as its argument.
  • Object – Passed as argument to script argument if script argument is a function. Null if takes no argument.
  • solidAngle – Solid angle that entity’s new presence queries with.
  • Mesh (optional) – uri corresponding to mesh you want to use for this entity. If undefined, defaults to self’s mesh.
  • scale (optional) – Scale of new mesh. (Higher number means increase mesh’s size.) If undefined, default to self’s scale.
  • Space (optional) – to create the entity in. If undefined, defaults to self.
Throws Exception:
 

Calling create_entity in a sandbox without the capabilities to create entities throws an exception.

Creates a new entity on the current entity host.

See also

system.canCreateEntity

createPresence(firstArg[, callback], A, A[, position][, space])
Arguments:
  • or object firstArg (string) – If string, will try to decode string as a mesh a uri for the new presence and callback argument is required. If it’s an object, we read the fields of the object for presence initialization information. The fields of the object we read are as follows: space (string), pos(vec3), orient (quat), mesh (string), physics (string), scale (float), callback (function), solidAngleQuery(float). Any of these parameters that are undefined default to taking the equivalent value of system.self.
  • callback (function) – function to be called when presence gets connected to the world. (Function has form func (pres), where pres contains the presence just connected.)
  • A (optional) – position for the new presence. Unspecified defaults to same position as self.
  • A – space to create the new presence in. Unspecified defaults to same space as self.
  • position (Vec3) – requested initial position for the presence. Ignored when using an object to specify settings.
  • space (string) – the space to connect to.
Throws Exception:
 

if sandbox does not have capability to

create presences.

Returns:

Nothing.

Creates a new presence for the entity. There are two ways to invoke this method. You can pass it an object containing properties to set (e.g. with fields ‘position’, ‘orientation’, etc) or pass it a fixed set of arguments (mesh, callback, position, space). Only the first method allows setting all properties of the presence and is preferred. In both cases, the second argument can be a callback to be invoked when the presence is connected.

By default, the presence’s intial position is the same as the presence that created it and its scale is 1.

See also

system.canCreatePresence

createVisible(string)
Arguments:
  • string (String*) – space and object id of a visible object.
Returns:

a visible object with the space and object id contained argument.

Throws an exception if string is incorrectly formatted, otherwise returns vis object.

deserialize(String)
Arguments:
  • String – to deserialize into an object.
Returns:

Returns an object representing the deserialized string.

disableRestoreScript(cb)
Arguments:
  • cb

Disable restoration from storage after a crash.

event(handler)
Arguments:
  • handler (function) – the event handler to invoke.
Throws TypeError:
 

if anything besides a function is provided

Returns:

true on success, false if the system is shutting down

Return type:

boolean

Trigger an event handler. The handler will be added to the event queue and invoked later, i.e. on a different stack than the current one.

getProxSet(presToGetSetFor)
Arguments:
  • presToGetSetFor (presence) – The presence object whose prox result set you want this function to return. If the presence object does not
Returns:

Each index of object is the identifier for a separate visible object. The value of that index is the visible itself.

Return type:

object

getScript()
Returns:returns the script that was set by setScript, and that is associated with this sandbox.
getVersion()
Returns:the version of the Emerson being run by the entity host

Gives the version of Emerson run by the entity host

import(scriptFile)
param String scriptFile:
 The Emerson file to import and execute in the current script
throws Exception:
 If the import leads to circular

dependencies, it will throw an exception. Use system.require to include each file only once.

Loads a file and evaluates its contents. Note that this version always imports the file, even if it was previously imported.

See also

system.require

isHeadless()
Returns:Returns true if you are running in headless mode. Returns false otherwise.
js_require(filename)
Arguments:
  • filename (String) – The path to look for the file to include

Loads and evaluates a file if it has not already been loaded. Unlike system.import, this ensures that each file is imported at most one time. This is usually what you want to use.

See also

system.import

killEntity()
Throws :__killEntity__ (If kill entity command is successful)
Throws :Exception (If do not execute kill entity from root context).

Destroys the entity and all the presences and state associated with it if run from the root context. If not run from root context, throws error.

onPresenceConnected(callback)
Arguments:
  • callback (Function) – The function to be invoked. Function takes a single argument that corresponds to the presence that just connected to the world.
Returns:

does not return anything

Registers a callback to be invoked when a presence created within this sandbox gets connected to the world

onPresenceDisconnected(callback)
Arguments:
  • callback (Function) – the function to be invoked. Function takes a single argument that corresponds to the presence that just got disconnected from the world.
Returns:

does not return anything

Registers a callback to be invoked when a presence created within this sandbox gets disconnected from the world.

prettyprint(a, obj2)
Arguments:
  • a (Object) – list of objects to print. Each of the objects are pretty-formatted concatenated before printing
  • obj2 (Object) –

prints the argument in javascript/json style string format

print(obj)
Arguments:
  • obj (Object) –

Prints the argument

See also

system.prettyPrint

println(obj)
Arguments:
  • obj (Object) –

Prints the argument, followed by a newline

See also

system.prettyPrint

require(filename)
Arguments:
  • filename (String) – The path to look for the file to include

Loads and evaluates a file if it has not already been loaded. Unlike system.import, this ensures that each file is imported at most one time. This is usually what you want to use.

See also

system.import

reset()
Returns:Does not return any value

Destroys all created objects, except presences in the root context. Then executes script associated with root context. (Use system.setScript to set this script.)

See also

system.setScript

restorePresence(isCleared, query)
Arguments:
  • string – sporef,
  • vec3 – pos,
  • vec3 – vel,
  • string – posTime,
  • quaternion – orient,
  • quaternion – orientVel,
  • string – orientTime,
  • string – mesh,
  • string – physics,
  • number – scale,
  • isCleared (boolean) –

    ,

  • uint32 – contextId,
  • boolean – isConnected,
  • function|null – connectedCallback,
  • boolean – isSuspended,
  • vec3 – suspendedVelocity,
  • quaternion – suspendedOrientationVelocity,
  • query (string) –
sendHome()
Returns:void
sendMessage(Which, Message, Visible)
Arguments:
  • Which – presence to send from.
  • Message – object to send.
  • Visible – to send to.
sendMessageUnreliable(Which, Message, Visible)
Arguments:
  • Which – presence to send from.
  • Message – object to send.
  • Visible – to send to.
sendSandbox(msg)
Arguments:
  • msg (object) – The message to deliver to sbox.
  • sandbox|util.sandbox.PARENT – (optional) sbox Should either be a sandbox object or should be the parent sandbox identifier. Marks the intended destination of msg. If undefined, just sends to parent.

Tries to send a message, msg, from the sandbox that system is instantiated in to sbox.

serialize(Object)
Arguments:
  • Object – to be serialized.
Returns:

Returns a string representing the serialized object. Takes an object and serializes it to be sent over the network, producing a string.

set_script()

Deprecated since version You: should use setScript

setRestoreScript(script, cb)
Arguments:
  • script
  • cb

Set the script to execute when this object is restored after a crash.

setScript(script)
Arguments:
  • script (String) – string representing the emerson script to be invoked
Returns:

does not return any value

Sets the script to be invoked when the system.reset is called

See also

system.reset

storageCommit()
Arguments:
  • function – (optional) callback to execute after commit is complete. This function takes two arguments: 1) bool (whether the commit succeeded or failed; 2) an object containing all the objects that we requested to read as fields (if we requested no reads, then this is undefined.
storageCount(cb)
Arguments:
  • countKeyStart. (String) – Specifies start of the range of keys in the backend storage system to count.
  • countKeyFinish. (String) – Specifies end of the range of keys in the backend storage system to count.
  • cb (function) – Callback to execute when count finishes. Takes two arguments: 1) bool (true if read succeeded, false if read failed); 2) If count succeeded, the int32_t value of the field read in (if count failed, undefined).
storageErase(eraseKey, cb)
Arguments:
  • eraseKey (String) – (same as writeKey from storageCommit and readKey from storageRead). Specifies the element in the backend storage system to remove.
  • cb (function) – Callback to execute when remove finishes. Takes a single argument: bool (true if remov is successful, false otherwise).
storageRangeErase(cb)
Arguments:
  • eraseKeyStart. (String) – Specifies start of the range of keys in the backend storage system to remove.
  • eraseKeyFinish. (String) – Specifies end of the range of keys in the backend storage system to remove.
  • cb (function) – Callback to execute when remove finishes. Takes a single argument: bool (true if remov is successful, false otherwise).
storageRangeRead(cb)
Arguments:
  • readKeyStart. (String) – Specifies start of the range of keys in the backend storage system to read data from.
  • readKeyFinish. (String) – Specifies end of the range of keys in the backend storage system to read data from.
  • cb (function) – Callback to execute when read finishes. Takes two arguments: 1) bool (true if read succeeded, false if read failed); 2) If read succeeded, the value of the field read in (if read failed, undefined).
storageRead(readKey, cb)
Arguments:
  • readKey (String) – (same as writeKey from storageCommit). Specifies the key in the backend storage system to read data from.
  • cb (function) – Callback to execute when read finishes. Takes two arguments: 1) bool (true if read succeeded, false if read failed); 2) If read succeeded, the value of the field read in (if read failed, undefined).
storageWrite(writeKey, data)
Arguments:
  • writeKey (String) – The field to write these data into. Later, can use writeKey to read from stored data.
  • data (String) – serialized data to put in storage.
  • function – (optional) cb Callback to execute when write has completed. Takes a single argument: bool as to whether the write succeeded (true) or failed (false).
timeout(time, callback, uint32, double, bool, bool)
Arguments:
  • time (Number) – number of seconds to wait before executing the callback
  • callback (function) – The function to invoke once “time” number of seconds have passed
  • uint32 (Reserved) – contextId
  • double (Reserved) – timeRemaining
  • bool (Reserved) – isSuspended
  • bool – isCleared
Returns:

a object representing a handle for this timer. This handle can be used in future to suspend and resume the timer

toString()
Returns:the string representation of the system object

See also

system.printsystem.prettyprint

wrapCallbackForSelf(cb)
Arguments:
  • cb

Wrap a callback in a function which restores system.self to the value when the callback was setup.

Attributes

presences

presences

Array