addObserver
Syntax
<Path>.addObserver(AttributeName:string, Method:object) |
The method addObserver adds an observer to the object designated by <Path>.
Parameters
The parameter AttributeName of data type string designates the name of the observable attribute or method.
When the value of this attribute or method changes, Plant Simulation calls the method designated by the parameter of data type object. It then executes the actions, which you programmed in this method.
Example
MyStation.addObserver("occupied", "myMethod") |
MyStation.addObserver("occupied", &myMethod) |
Within the called Method you can use the anonymous identifiers ? and @ to address the object, whose attribute changed, i.e., the caller of the Method.
Two parameters are passed to the Method, which will be executed:
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.
The previous value of the observable attribute or the observable method. This way you can still access the previous value after the Method changed it to the new value.
The Method to be executed might look like this:
param attribute: string, oldValue: any
if ?.occupied
?.Cont.move(Station2)
end
Related Topics
Related Topics
General Methods of All ObjectsattributeWatchable
closeDialog (all objects)
deleteObject
derive
duplicate
extendPath
getHTMLCode (all objects)
getObservers
getXYWH
hasAttribute (2D)
isNameUnique (identifier)
memUsage
moveToFolder
openDialog (all objects)
print (all objects)
removeAllObservers
removeObserver
replace
setName
setPosition
setXYWH
updateDialog
writeObject