2

I would like to give the user a button that allows them to skip ahead 1 hour in the simulation and then continue running the model if play is clicked. The code below allows the user to skip ahead an hour, however they are unable to resume the simulation when play is clicked.

double nextHour = time() + 60;
pauseSimulation();
getEngine().runFast(nextHour); //Runs the model to the next hour when button is clicked

Any help much appreciated.

Stuey.I
  • 133
  • 1
  • 1
  • 6

2 Answers2

3

Try adding runSimulation() after the last line. But probably, that does not work. In that case:

Create a dynamic event (not the normal event) with the line runSimulation() in its action code.

In the button code, before the runFast... line, write create_MyDynamicEvent(1, HOUR). This will trigger the even 1 hour later and unpause the model.

Benjamin
  • 10,603
  • 3
  • 16
  • 28
2

AnyLogic Support suggested the following solution, which I have used:

enter image description here

Unfortunately, Ben's suggestion didn't didn't work; it seems to cause an issue when pauseSimulation() is used.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Stuey.I
  • 133
  • 1
  • 1
  • 6
  • fair, thx for sharing – Benjamin Dec 10 '21 at 06:37
  • Can you move the commentary out of your answer and to a comment under @Benjamin's answer? That will make it easier for future readers to understand the context of the feedback when reviewing answers. – Jeremy Caney Dec 11 '21 at 01:27