> For the complete documentation index, see [llms.txt](https://docs.monokot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.monokot.io/scripts/api/context.md).

# Context

Context object is an input point for accessing context-dependent objects, their methods and fields.

### Fields <a href="#h.pt685fx1cysm" id="h.pt685fx1cysm"></a>

| **Name**       | **Description**                                                                                                    |
| -------------- | ------------------------------------------------------------------------------------------------------------------ |
| expression     | Contains an object of Expression type with information about the expression being executed                         |
| currentTrigger | Contains the name of the trigger that initiated the execution of the expression (string)                           |
| data           | Contains an object of DataMap type for obtaining values of data triggers **at the moment of expression execution** |
| bundle         | Contains a Bundle object for transferring data between expressions                                                 |
| token          | Intended to store arbitrary data obtained during the execution of an expression                                    |
| signalTime     | Contains the time when the trigger was fired                                                                       |

### Examples <a href="#h.h10gzdvqrn8e" id="h.h10gzdvqrn8e"></a>

The following example demonstrates a script that adds 1 or 1000 to the current value of the expression, depending on which of the triggers was activated. In this example, the expression has two periodic triggers at intervals of 100 ms (*trig\_100ms*) and 1000 ms (*trig\_1000ms*).

```javascript
// For brevity, we will save the current value of the expression in a variable
var val = context.expression.currentState.value;

// Summarization
if (context.currentTrigger == 'trig_100ms')
  return val + 1;
else if (context.currentTrigger == 'trig_1000ms')
  return val + 1000;
else return MosUtils.doNothing;
```

The next example demonstrates the use of the *token* property. The code in the listing returns the arithmetic mean of the last three values obtained from the tag. This is possible because the value of the *token* property is stored and available during the next execution of the expression. In this example, the expression has a data trigger (*trig\_number*) with a numeric tag.

```javascript
// For brevity, we will save the current tag value in a variable
var tagValue = context.data['tag_number'].state.value;

// If the script is executed for the first time, we initiate an array of 3 elements in token
if (context.token == null)
{
  context.token = new Array(3);
  context.token[0] = 0;
  context.token[1] = 0;
  context.token[2] = tagValue;
}
else {    
  // ...otherwise, we “shift” the array elements
  context.token[0] = context.token[1];
  context.token[1] = context.token[2];
  context.token[2] = tagValue;
}

return (context.token[0] + context.token[1] + context.token[2]) / 3;
```
