How correctly to work with Anylogic getEngine().step() function?

42 Views Asked by At

I have a problem with statechart in my model. For example if I write statechart.fireevent("1") witch change active state1 to state2, it doesn't change it instantly, but through the "atomic delay". If I asked what is the activestate in the second line code (after making fireevent) Anylogic says that it is state1 (the activestate has not changed yet). It is make a lot of difficulties for me while programming code.

I found in Anylogic help an interesting function getEngine().step() Witch as I understand doing what I want. If I place it after fireevent method statechart changes it's state, and only after it completes the second line of my code execute, and Anylogic says that active state is now state2! Great, because it solves for me many difficulties.

But if read Anylogic help carefully, there is a strange phrase written there that, as I understand it, this function can only be called for a model that is in a pause state:

*

Makes at most one discrete step of the model (can be done from the PAUSED state only)

! I tested it for the model that was running, everything also works correctly. it is not clear why the pause is and how important it is. if this leads to incorrect results, then I can artificially put the model into pause mode, call step() function inside code, and then return the model to run() mode again (but it's seems to be unnecessarily complicated)

What do you think about it?

1

There are 1 best solutions below

3
Benjamin On

Dont use it, it is really advanced and not necessary.

Instead of fireEvent, you can use the statechart.receiveMessage()

It is consumed directly (fireEvent writes itself to into the engineto be executed in the next step). Also see the help and example models, they go deeper into this.