.. |parameter-button| image:: /medias/desktop/choregraphe/parameter_button.png :class: img-inline .. _choregraphe-reference: .. _choregraphe-reference-loading-unloading: Loading, unloading, starting and stopping a behavior, a box, a diagram or a timeline ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Behavior When a :ref:`behavior ` is **loaded**: #. All :ref:`boxes ` contained in the behavior are **constructed**. So the constructor of each box ``__init__`` is called. #. Its :ref:`diagram ` is **loaded**. When it is **unloaded**: #. Its :ref:`diagram ` is **unloaded**. #. All :ref:`boxes ` contained in the behavior are **destroyed**. When it is **started** (or **played**): #. The behavior is **loaded**. #. Its **onStart** :ref:`input ` is **stimulated**. When it is **stopped**, it is **unloaded**. Box When a :ref:`box ` is **loaded**, the ``onLoad`` function of its :ref:`script ` is called. For further details about this kind of built-in functions, see the section: :ref:`choregraphe-reference-box-script-built-in-functions`. When it is **unloaded**: #. The ``onUnload`` function of its :ref:`script ` is called. #. Its :ref:`diagram ` or its :ref:`timeline ` is **unloaded**. When it is **started** (with an **onStart** :ref:`input `): #. The ``onInput_`` function of its :ref:`script ` is called. #. Its :ref:`diagram ` or its :ref:`timeline ` is **loaded**. #. If it is a :ref:`flow diagram box `, then the signal received on the **onStart** input is transmitted to the :ref:`diagram ` of the box. If it is a :ref:`timeline box `, then its :ref:`time cursor ` is played. So it starts being regularly incremented. When it is **started** but its :ref:`resources ` are not available and even after the timeout specified they are still unavailable: * If a function named ``onResourceError`` is defined in the :ref:`box script `, it is called. * Else, the :ref:`output ` named ``onStopped`` is stimulated (if any). When it is **stopped** with an **onStop** :ref:`input `: #. The ``onInput_`` function of its :ref:`script ` is called. #. Its :ref:`diagram ` or its :ref:`timeline ` is **unloaded**. When it is **stopped** with an **onStopped** :ref:`output `: #. Its :ref:`diagram ` or its :ref:`timeline ` is **unloaded**. #. The signal received on the **onStopped** output is transmitted to the parent :ref:`diagram `. When it is **stopped** because its :ref:`resources ` are set to **Stop on demand** and they are asked by another box: #. If a function named ``onResourceLost`` is defined in the :ref:`box script `, it is called. #. The :ref:`diagram ` or the :ref:`timeline ` of the box is **unloaded**. #. If there was no ``onResourceLost`` function defined in the script, the :ref:`output ` named ``onStopped`` is stimulated (if any). .. note:: Sometimes it can take some time for a behavior to stop. For instance, if NAO is walking, the "Walk" behavior you want to stop will wait for NAO's feet to be stable before stopping, so that the robot doesn't fall down. Flow diagram When a :ref:`diagram ` is **loaded**: #. The :ref:`boxes ` within the diagram are **loaded**. #. The **links** between these boxes are activated. Note that before this step the stimulation of any :abbr:`I/O (input/output)` within the diagram would be unefficient. #. The **onLoad** :ref:`input ` of the diagram (if any) is stimulated. When it is **unloaded**: #. The **links** between the :ref:`boxes ` within the diagram are broken. Note that after this step the stimulation of any :abbr:`I/O (input/output)` within the diagram would be unefficient. #. These boxes are **unloaded**. Timeline When a :ref:`timeline ` is **loaded**: #. The :ref:`time cursor ` is set to the :ref:`start frame `. #. The :ref:`diagrams ` of the :ref:`behavior keyframes ` present on this frame are **loaded**. When it is **unloaded**: #. The :ref:`time cursor ` is paused. So it stops being incremented. #. The :ref:`diagrams ` of the :ref:`behavior keyframes ` present on this frame are **unloaded**. #. The :ref:`time cursor ` is set to -1.