> 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/programming-examples/how-to-do-simulation.md).

# How to: Do Simulation

The guide demonstrates how to create expressions that generate a sinusoidal signal and a saw signal for simulation and testing purposes.

Open Monokot Server Administrator and double-click *Scripts* on the *Server Explorer* pane. Click *New Expression* and set the name *Sin* for the expression that appears. Insert the following code into the expression code editor:&#x20;

```javascript
// "token" is a property in which you can put a custom value that 
// will be available during the next code execution
context.token += 0.1;

var value = Math.sin(context.token) * 50;
return value;
```

Go to the *Triggers* tab and click *Add Periodic*. Now, we have created an expression that will be executed every 500 ms.

<figure><img src="/files/Bv0SR7qCofd0fJMCw3YH" alt=""><figcaption></figcaption></figure>

In the same way, create a second expression named *Saw* and specify a periodic trigger for it, but to simulate the saw signal, use the following code:

```javascript
// ...by default, token is null
if (context.token == null)
    context.token = 0;
else context.token += 1;

if (context.token > 50)
    context.token = -50;

var value = context.token;
return value;
```

In order for the changes to take effect on the server, click the Sync button. Now, if you write the data (for example, in InfluxDB) generated by these expressions, you will see something similar as in the figure below:

![](/files/K7zKeDOeXAX4oXzbgdOA)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.monokot.io/scripts/programming-examples/how-to-do-simulation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
