Moogsoft Docs

Constants

Description

Each MooBot runs in its own thread, and instances of MooBots are independent of each other. The Constants module enables the sharing of logic, states or flags between MooBots . It allows you to 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 you are interested in listening for. See the Event types table under constants.eventType() .

The Constants module is available to load into any standard MooBot.

To use , at the top of a MooBot js file , define a new global object constants to load the Constants module:

var constants = MooBot.loadModule('Constants');

Reference Guide


constants.put

constants.put()

Associates the specified value with the specified key .

Previous key mapping has the old value replaced.

Request Argument

Name Type Description
key
String The key with which the specified value is to be associated
value
Object The value associated with the key

Return Parameter

Void - no value returned
constants.get

constants. get(key)

Returns the value to which the specified key is mapped.

Request Argument

Name Type Description
key
String The key indicating where to retrieve the value

R eturn Parameter

Type Description
Object The value to which key is mapped, or null if there is no mapping
constants.contains

constants.contains()

Returns a positive response if the module contains an object with the specified name.

Request Argument

Name Type Description
name
String The object name

R eturn Parameter

Type Description
Boolean true if the module contains an object with that name, otherwise false

constants.remove

constants.remove()

Removes the value to which the specified key is mapped

Request Argument

Name Type Description
key
String The key with which the value will be removed


Return Parameter

Void - no value returned

constants.eventType

constants. eventType()

Returns a CEvent object for a range of valid Event types.

Request Argument

Name Type Description
<name>
String The name of the Event type. See below

Event types:

Name Passed Description
E_LamEvent
(“Event”/"Events") A raw Event from a LAM
E_NewAlert
(“Alert”/"Alerts") New Alert
E_AlertUpdate
(“AlertUpdate”) Alert update
E_CloseAlert
(“AlertClose”) Close Alert
E_NewComment
("Comment"/"Comments") New Comment
E_NewFeedback
("Feedback") New Feedback
E_NewSig
(“Sig") New Situation
E_SigClose
("SigClose") Close Situation
E_SigUpdate
(“SigUpdate”) Updated Situation
E_SigStatus
("SigStatus") Situation status
E_SigAction
("SigAction") Situation action
E_ThreadEntry
("ThreadEntry") A thread entry
E_NewThreadEntry
("NewThreadEntry") A new thread entry
E_Summary
("Summary") System summary
E_Invite
(“Invitation”) Situation Room invitation
E_User
(“User”) The user name
E_Unknown
(“Unknown”) An Event which is uncategorised (an error condition)

As Moogsoft enhances and develops the system, more Event types may be added.

R eturn Parameter

Type Description
CEvent A CEvent object containing the value for 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 .

  • put () takes the name of the variable you want to store counter , and the variable count .

You can later retrieve a value by calling the method get () and passing the name of the shared attribute you want, which is returned as a JavaScript local variable.

var count_val=constants.get("counter");
count_val++; 
constants.put("counter",count_val);
  • get takes the name of the shared attribute, counter
  • count_val is incremented
  • put takes the name of the variable you want to store, counter , and the incremented value, count_val

If you do not have anything stored under counter , the MooBot returns the JavaScript object null .

eventType Example

The following eventType() example passes the name of an Event and returns a system wide Constant which identifies that type of Event when using the Events module.


constants.eventType("Event")