Tinderbox v11 Icon

Querying Lists and Sets

Testing (querying) containment in lists

Testing List and Set type attribute, the contains() or list.contains() operators, return true if a List-type—or Set-type—list contains an exact match for the the designated regex. The test is case-sensitive regardless of agent query case sensitivity settings; regex matches are not supported. If user attribute PetTypes has a value of [dogs;cats] then

$PetTypes.contains("dogs") is true,

but

$PetTypes.contains("dog") is false 

as 'dog' is an incomplete value match.

It can be useful to use a stored value as the search regex, for instance using the name of an agent as the search term. However, the following will not work or an agent named 'dogs':

$PetTypes.contains($Name) WRONG!

Instead, use the evaluated result of the above via a rule or some other action code. Thus, in an agent's Rule box, enter:

$AgentQuery='$PetTypes.contains("'+$Name+'")' 

…which results in a query of:

$PetTypes.contains("dogs") 

Querying list items

A query can test a single item from a list. For instance, if $MyList for note A is [3;4;5] and for note B is [1;5;10], then query:

$MyList[1]==$MyNumber(agent) 

will match B but not A. This is because only B has the number 5 as the second list item ('1' in a zero-based list).

Further information

See Set Attributes and List Attributes for more on list-based attributes.


See also—notes linking to here: