# Token simulation playback

**URL:** <https://forum.bpmn.io/t/token-simulation-playback/7187>\
**Category:** Users\
**Created:** [February 9, 2022, 6:09pm UTC](https://forum.bpmn.io/t/token-simulation-playback/7187 "2022-02-09T18:09:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajgoel](https://forum.bpmn.io/user_avatar/forum.bpmn.io/rajgoel/32/2067_2.png) [@rajgoel](https://forum.bpmn.io/u/rajgoel)\
**Post date:** [February 9, 2022, 6:09pm UTC](https://forum.bpmn.io/t/token-simulation-playback/7187/1 "2022-02-09T18:09:38Z")

</div>

@nikku Is there any way to save the event log of the token simulation in a way that a playback is possible (without having to trigger the play buttons for events, gateway selections, etc.)?

Of course the token simulation can be recorded as video, but that is comparably heavy and prevents any interaction like zoom in/out.

Btw. what is the easiest way for you to create the animated gifs that are used to showcase examples? So far I haven’t found a nice way and any hint would be appreciated.

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [February 9, 2022, 6:23pm UTC](https://forum.bpmn.io/t/token-simulation-playback/7187/2 "2022-02-09T18:23:31Z")

</div>

> [@rajgoel](#):
>
> Is there any way to save the event log of the token simulation in a way that a playback is possible (without having to trigger the play buttons for events, gateway selections, etc.)?

Yes there is. Essentially [any test case](https://github.com/bpmn-io/bpmn-js-token-simulation/blob/master/test/spec/SimulationSpec.js#L126) is a play back scenario.

Details however really depend on your case. What do you need the record + playback for? How much human interaction is required?

> Btw. what is the easiest way for you to create the animated gifs that are used to showcase examples?

I’m a GIF dude so I setup my very own little recording facilities. There does exist a couple of good recording tools out there, simply search for them (depending on your OS).

---

<div class="post-metadata">

**Author:** ![rajgoel](https://forum.bpmn.io/user_avatar/forum.bpmn.io/rajgoel/32/2067_2.png) [@rajgoel](https://forum.bpmn.io/u/rajgoel)\
**Post date:** [February 10, 2022, 10:55am UTC](https://forum.bpmn.io/t/token-simulation-playback/7187/3 "2022-02-10T10:55:22Z")

</div>

I am currently still exploring the possibilities and the current advances in the token simulation project are opening multiple avenues (kudos). Some of the use cases I see for me:

- Integration in [Reveal.js](https://revealjs.com/) for slidedecks explaining BPMN (possibly via a new plugin for Reveals.js). Here, it would be nice to be able to showcase different token flows for the same process without any user interaction except for start playback/stop playback.
- Tutorials for custom extensions of BPMN for which the token flow at custom elements may have a special behaviour.
- Visualisation of token flows logged from an execution engine.

I’ll try to understand the test case implementation and will see whether I can make any of the above work.

The logic with `triggerElement( name )` and `await elementEnter( name )` looks quite intuitive. But where would I put this if I have a setup like this?

```auto
var modeler = new BpmnModeler({
  container: '#canvas',
  propertiesPanel: {
    parent: '#properties-panel'
  },
  additionalModules: [
   propertiesPanelModule,
   TokenSimulationModule
  ],
});

modeler.importXML( sampleProcess );

```

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [February 11, 2022, 12:30pm UTC](https://forum.bpmn.io/t/token-simulation-playback/7187/4 "2022-02-11T12:30:12Z")

</div>

KUDOs to you, too, for giving it a try! It is feature complete since [`v0.25.0`](https://github.com/bpmn-io/bpmn-js-token-simulation/blob/master/CHANGELOG.md#0250) so a good time to play around with it.

It should be fairly easy for you to extract what is in that test to a re-usable component.

For experimental purposes I’ve done that in [this codesandbox](https://codesandbox.io/s/amazing-christian-ry9yw?file=/src/index.js). What you get as a result is a click-and-play experience.

![capture.SbFRc9_optimized](https://forum.bpmn.io/uploads/default/original/2X/0/03bfcb1acefc9473f382deda16752bfe4a21ba33.gif)

Drive the process via API:

```javascript
const simulationSupport = modeler.get("simulationSupport");

// toggle pause on activity
simulationSupport.triggerElement("Activity_1jmvmoa");

// start simulation
simulationSupport.triggerElement("StartEvent_1");

await simulationSupport.elementEnter("Activity_1jmvmoa");

window.alert("WANT ME TO CONTINUE?");

// trigger un-pause
simulationSupport.triggerElement("Activity_1jmvmoa");

```

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [February 11, 2022, 7:29pm UTC](https://forum.bpmn.io/t/token-simulation-playback/7187/5 "2022-02-11T19:29:46Z")

</div>

Released as a [dedicated module](https://github.com/bpmn-io/bpmn-js-token-simulation/blob/master/docs/simulation-support/README.md#readme) with `token-simulation@0.26.0`.

---

<div class="post-metadata">

**Author:** ![rajgoel](https://forum.bpmn.io/user_avatar/forum.bpmn.io/rajgoel/32/2067_2.png) [@rajgoel](https://forum.bpmn.io/u/rajgoel)\
**Post date:** [March 14, 2025, 12:00pm UTC](https://forum.bpmn.io/t/token-simulation-playback/7187/6 "2025-03-14T12:00:36Z")

</div>

Just came back to this and was asking myself whether the API of the simulation support module should support an (optional) parameter for the id of the token to be advanced.

```js
  // start simulation
  simulationSupport.triggerElement("StartEvent_1"); // Token 1
  await simulationSupport.elementEnter("Activity_1jmvmoa"); // Token 1
  simulationSupport.triggerElement("StartEvent_1"); // Token 2
  await simulationSupport.elementEnter("Activity_1jmvmoa"); // Token 2
  simulationSupport.triggerElement("Activity_1jmvmoa"); // Token 2 <== doesn't work without additional parameter
  simulationSupport.triggerElement("Activity_1jmvmoa"); // Token 1

```

If I create multiple tokens like above, I may want to advance a specific token first, thus allowing, e.g. the second token to overtake the first.

With such a parameter I could have full control over the token movments, e.g. like this:

```js
  // start simulation
  simulationSupport.triggerElement("StartEvent_1", "Token_1"); // Create token with id "Token_1"
  await simulationSupport.elementEnter("Activity_1jmvmoa", "Token_1");
  simulationSupport.triggerElement("StartEvent_1", "Token_2"); // Create token with id "Token_2"
  await simulationSupport.elementEnter("Activity_1jmvmoa", "Token_2");
  simulationSupport.triggerElement("Activity_1jmvmoa", "Token_2");
  simulationSupport.triggerElement("Activity_1jmvmoa", "Token_1");

```

---

<div class="post-metadata">

**Author:** ![nikku](https://forum.bpmn.io/user_avatar/forum.bpmn.io/nikku/32/5130_2.png) [@nikku](https://forum.bpmn.io/u/nikku)\
**Post date:** [March 14, 2025, 5:29pm UTC](https://forum.bpmn.io/t/token-simulation-playback/7187/7 "2025-03-14T17:29:14Z")

</div>

I think this makes sense, aligns with [other things we did recently](https://github.com/bpmn-io/bpmn-js-token-simulation/commit/799c63b094ac93dbdf200ad6b73fba121237292b) to make the simulation support module more versatile. This would probably not be the `TokenID`, but the ID of the parent scope.

---

<div class="post-metadata">

**Author:** ![barmac](https://forum.bpmn.io/user_avatar/forum.bpmn.io/barmac/32/974_2.png) [@barmac](https://forum.bpmn.io/u/barmac)\
**Post date:** [July 9, 2025, 10:09am UTC](https://forum.bpmn.io/t/token-simulation-playback/7187/8 "2025-07-09T10:09:48Z")

</div>

Closed on July 9, 2025, 10:09am UTC

Closing old topics.
