Reputation: 293
I want my simulation to stop as soon as a specific condition in the code is met. By 'stop' I mean it should pause the simulation as if I pressed stop button in the simulation window. So that I could continue the simulation with a slower speed from this moment.
Is there a way to do it from the module code?
Upvotes: 1
Views: 1384
Reputation: 7012
The alert()
method is very convenient to implement @Rudi trick.
In GUI (Run, Fast, and Express) alert()
pauses the simulation, shows a message box with own text, waits for user reaction, and then continues the simulation in the same mode. In Cmdenv
it shows a text in console without pausing a simulation.
Here is a sample code that prints current event number using this method:
char text[128];
sprintf(text,"Event number: %lld", getSimulation()->getEventNumber());
getSimulation()->getActiveEnvir()->alert(text);
After learning this event number one should do what @Rudi has proposed in the last bullet.
Upvotes: 1
Reputation: 6681
There is no API for managing the GUI's run state. The reason is, that you can run the simulation also in Cmdenv without recompiling the code and it's not possible/makes no sense to pause a simulation in Cmdenv.
You can however do a trick, because the simulation is repeatable:
Upvotes: 2