Model Initialization Order
It may be helpful to understand the model initialization order in
terms of ordering of various operations.
- The top-level agent of the model (Main)
is constructed, its parameters are set up, and its function create() is called. The parameters are
set up in the same order in which they are presented in the Parameters preview section
of the agent type properties. Dynamic variables are initialized,
animation is created. The function create()
does the same steps for all its embedded objects. At this point
creation of the model and the animation is completed.
- The function start() for each
object is called. Each object creates and initializes its
statecharts (each statechart enters its initial state) and
events. Finally On startup
code is executed, first on the innermost objects and then up
along the model tree. The On
startup code of the Main
agent type is executed the last.
- The model execution is started.
So, On startup code is
executed at the final stage of model initialization, after all
objects throughout the entire model have been constructed,
connected, and initialized, and before anything else is done. This
is a place for some additional initialization and starting
object’s activities such as events.