Class Capture Selector
Sometimes you may want to check if an object has a class, and see if the sub-object that class represents has a certain value or use a certain value, but you don't want to go into the class, or can't if you for example are adding another sub-object to the parent that depends on that value. With the selectors that currently exist, that'd require having to write some form of function instead to search the current object for that class and the value you want from that class. This is why the class capture selector exists. It allows you to select objects with a class, and run expressions on the sub-objects representing those classes and bring them into the scope of your current object.
Using the Class Capture Selector.
The class capture selector starts off the same way as the class selector, with the .class-name
, but it is followed by a :[...]
, where the ...
is a list of function statements to run in the scope of the sub-object that the class represents. In this scope, you get access to the $$field-name
implicit variables, and the $current
implicit variable as well. Any variables you define here though get passed back out of the selector into the selection block the selector is attached to.
For an example of how this works, here is a patch which will add a module to all parts that have an antenna, but have the data of that module be based off of the communication range of the part's antenna.