More on message passing
November 11th, 2005
Anyone who’s downloaded the latest Mage/Fishink will see that Dennis is now saying things in response to events. For example: Turn on the light switch and he says, “Light goes on.” and likewise, turn it off, and he says, “Light goes off.” This is just another example of the Signal/Slot mechanism: When A occurs, B should occur.
It seemed about time that I started working more on the flexibility of Signal/Slot linkages. So first of all, I added two new Messenger methods:
signalSetFlag(Signal, Flag); signalUnsetFlag(Signal, Flag);
These methods make it possible to link the occurance of a Signal to the setting of a flag. I then modifed Slot to introduce an (optional) required flag. Therefore, it’s possible to do this:
messenger.signalSetFlag(
Signal(DIRTY_TISSUES,
Signal_IsManipulated,
true),
HAS_DIRTY_TISSUES);
The above says that when DIRTY_TISSUES are manipulated (picked up), the flag HAS_DIRTY_TISSUES will be set.
messenger.link(
Signal(TISSUE_BOX,
Signal_IsManipulated,
true),
Slot (HAS_DIRTY_TISSUES,
DENNIS,
Slot_Say,
"No, need... I have dirty ones!");
This part says that when TISSUE_BOX is manipulated (clicked) and HAS_DIRTY_TISSUES has been set, DENNIS will say, “No, need… I have dirty ones!”
This feature, as always, is not without its limitations. For example, it’s not possible to say that a slot requires the absense of a flag. The following is an example of something that is not possible.
messenger.link(
Signal(BEDSPREAD,
Signal_IsManipulated,
true),
Slot (! AWARE_OF_HOLE_UNDER_BED,
DENNIS,
Slot_Say,
"Neato! There's a hole under my bed!");
There are ways around it however, and I’ve exercised these ways in the latest build. Another limitation is that a slot cannot rely on the presence (or absense) of several flags. I can see several places that this might come in handy, and I’ll begin work on it soon.