Sensor Registration

From ABL
Jump to: navigation, search

Sensed WMEs are registered with sensors. The ABL sensor registration syntax is:

register SensorWME with Sensor;

For example, in ABL-Wargus, the sensor that senses information about the available units (e.g. peasant, footman) is registered with the UnitWME as follows:

register UnitWME with UnitSensor;

The registration of a WME with a sensor tells ABL that the sensor "owns" the WME. ABL is responsible for making sure that in the normal course of execution, whenever the WME is referenced (appears in a test), it contains an up-to-date value.

For example, if a daemon is waiting on the creation of the first footman, the daemon's success test just contains a test of UnitWME:

with (success_test{ (UnitWME type == HUMAN_FOOTMAN) }) wait;

ABL makes sure that initializeContinuous is called on the UnitSensor when the daemon test first enters the ABT, that senseContinuous is called repeatedly while the test remains in the ABT, and that unit sensing stops when the test leaves the ABT. If a reference to UnitWME appears in a precondition, senseOneShot will be called on UnitSensor before the precondition is tested. ABL reference counts sensors participating in continuous conditions in order to share sensing across multiple conditions referencing the same sensed WME. User code should be careful of directly modifying registered WMEs, as the ABL runtime will change them without notice if it detects that sensing is required. User code that wants to save a previously sensed value should store a copy of the value in a WME class not registered on a sensor.