Constants
Each Moobot runs in its own thread and instances of Moobots are independent of each other. The Constants module enables you to share logic, states or flags between Moobots. You can build a key value dictionary mapping that is shared across Moobot instances.
There are many system wide defined Constants that are used in the Events module to define which event to listen for. See the event types table below for more information.
Load the module
The Constants module is available to load into any standard Moobot. To load it, define a new global variable at the top of the Moobot Javascript file. For example:
var constants = MooBot.loadModule('Constants');
Method reference
The Constants module uses the following methods.
put
Associated a specified value with a specified key. Replaces the mapping for an existing key.
Request arguments
The method takes the following arguments.
Name |
Type |
Description |
---|---|---|
|
String |
The key to associate with the value. |
|
Object |
The value to associate with the key. |
Response
None.
get
Retrieves the value mapped to a specified key.
Request arguments
The method takes the following arguments.
Name |
Type |
Description |
---|---|---|
|
String |
The key for which to retrieve the value. |
Response
The method returns the following parameter:
Type |
Description |
---|---|
|
The value to which the key is mapped, or null if no mapping exists. |
contains
Returns a positive response if the module contains an object with the specified name.
Request argument
The method takes the following arguments:
Name |
Type |
Description |
---|---|---|
|
String |
The Object name. |
Response
The method returns the following parameter:
Type |
Description |
---|---|
|
True if the module contains the specified object, otherwise false. |
remove
Removes the value mapped to the specified key.
Request arguments
The method takes the following arguments:
Name |
Type |
Description |
---|---|---|
|
String |
The key for which the value is to be removed. |
Response
None.
eventType
Retrieves the value of a specified event type.
Request arguments
The method takes the following arguments:
Name |
Type |
Description |
---|---|---|
|
String |
The name of the event type. See the list of event types in the table below. |
Event types
You can use one of the following event types in the name argument:
Name |
Passed Value |
Description |
---|---|---|
|
|
Raw event from a LAM |
|
|
New alert |
|
|
Alert update |
|
|
Close alert |
|
|
New comment |
|
|
New feedback |
|
|
New Situation |
|
|
Close Situation |
|
|
Updated Situation |
|
|
Situation status |
|
|
Situation action |
|
|
A thread entry |
|
|
A new thread entry |
|
|
System summary |
|
|
Situation Room invitation |
|
|
Username |
|
|
An uncategorized event (error condition) |
Response
The method returns the following parameter:
Type |
Description |
---|---|
CEvent |
An object containing the value of the specified event type. |
Examples
The following example in AlertBuilder.js
shows the Constants module
with two methods that allow you to post and retrieve values from a shared scratchpad.
var count=0 constants.put("counter",count);
The variable count is set to 0 and stored using the label counter
.
You can then retrieve a value by calling the get
method and passing the
name of the shared attribute, which is returned as a JavaScript local variable.
var count_val=constants.get("counter"); count_val++; constants.put("counter",count_val);
-
The
get
method takes the name of the shared attribute, "counter". -
The variable
count_val
is incremented. -
The
put
method takes the name of the variable to store, "counter", and the incremented valuecount_val
.
If nothing is stored in counter
, the Moobot returns null
.
The following example passes the name of an event and returns a system wide constant that identifies that type of event when using the Events module.
constants.eventType("Event")