Edit Observers (described)

The menu command Edit Observers opens the dialog Edit Observers. Here you can create observers, which observe the values of observable attributes and methods and which enable you to react to changed values.

When you create your simulation model, it will often become necessary to trigger certain actions, when the values of observable attributes or observable methods of objects change. To accomplish this, you can create observers for most of the built-in objects.

This observer observes the value of an attribute or a method and then executes one or several methods. This method can either be a Method object, which you insert into a Frame, or a user-defined attribute of data type method.

An observer of a user-defined attribute of data types table/list/stack/queue is not going to be called when the contents of the list changes, but only when a new list is assigned. In addition the old list will not be passed to the second parameter of the observer method, but this parameter is always VOID for lists.

Within the Method, you can use the anonymous identifiers ? and @ to address the object, whose attribute changed, i.e., the caller of the Method.

Parameters

The program passes one, two, or three parameters to the Method, which will be executed:

param attribute: string, oldValue, newValue: any
  1. The name of the observable attribute or the observable method, whose value changed. This way you can use a single Method as the called Method for several attributes/methods.

  2. The previous value of the observed attribute or the observed method. This way you can still access the previous value after the Method changed it to the new value.

  3. The new value of the served attribute or the observed method.

You can either omit the first two parameters or the last parameter. Thus you can declare observer methods with one, two, or three parameters:

Syntax

-- 1 parameter, without parameter 1 and 2 
param newValue: any

-- 2 parameters, without parameter 3
param attribute: string, oldValue: any

-- 3 Parameter
param attribute: string, oldValue, newValue: any

Proceed as follows to work with observer methods:

  • To create a new observer, click New.

  • To edit an existing observer, select it in the list field and click Edit or double-click it in the list field.

  • To delete an observer, select it in the list field and click Delete.

You can use these keyboard keys in the list:

  • Return to open the dialog Select Observing Method of the selected observer. Here you can then change the settings.

  • Insert to create a new observer.

  • Delete to delete the selected observer. When you cleared the check box Confirm under File > Preferences > Modeling > Delete objects, Plant Simulation deletes the observer without prompting you to confirm.

    Note:

    As a rule observer methods are called after all other controls. If you want to react to state changes before other controls, you have to use the stopuntil instruction or the waituntil instruction instead of an observer.

Compare the sample models: Click the Window ribbon tab, click Start Page > Getting Started > Example Models and click Small Examples. Then, select the respective Category, the Topic, and the Example in the dialog Examples Collection and click Open Model.

Related Topics

Create and Delete an Observer

addObserver

attributeWatchable

getObservers

removeObserver