Queries are used by:
- agents
- action code conditional statements
- action find() operators (most normally for scoping arguments)
Queries are written in action code syntax but with some differences:
- Queries never use semi-colon terminators unlike in rules, etc.
- Equality tests (are two things the same?) always use a == operator (two equals signs).
- Note: very old code examples may use a single '=' and if using copy paste do not forget to double the = to ==.
- If a query has multiple parts, these are joined using & (and) or | (or) join characters.
If it is desired to control the order in which different parts of a multi-term query are evaluated, each query term—or sub-groups of query—can be enclosed in parentheses, i.e. round brackets '(' and ')'. As with parentheses in a spreadsheet formula, Tinderbox will evaluate the inner-most (most deeply nested) parentheses before working outwards until the whole query is evaluated.
Action code offset addresses can be used, i.e. referencing values in another note $Color
versus $Color("Some other note")
. In the special case of wanting to reference attribute values in the agent itself, use the 'agent' designator to refer to the attributes of the current agent, whilst smart adornments can similarly use the 'adornment' designator. For example:
Query: $Status=="Important"
Action: $Color=$Color(agent)
This agent gathers all "Important" notes and sets their colour to match the colour of the agent. Note that this is different from
Action: $Color=$Color(this)
since "this" refers to the note being gathered, and is also different from
Action: $Color=$Color(parent)
since "parent" is the parent of the original note, not the parent of the newly-made alias. The latter is a case where, for intrinsic attributes, it may be necessary to use the 'original' designator to avoid using the aliases value for the attribute. Thus:
Action: $Color=$Color(parent(original))
More on Queries
See:
- Simple Queries - equality and inequality
- String Attributes - comparison operators & case sensitivity
- Querying Lists and Sets
- Regular Expressions in queries
- Legacy Query Code for agents
See also—notes linking to here: