This version is out of date, covering development from v8.0.0 to v8.x.x. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v8 Icon

action(code)


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Altered: 

 Function   [other Function type actions]

 Item   [operators of similar scope]

 Data manipulation   [other Data manipulation operators]

 Baseline

 


action(code)

This function allows execution of code without the need for a return value. This lets an action in an attribute, $Text being useful for long complex actions, and perform that action as part of a rule or agent action.

For example, the Rule

action('$Color= "bright red"');

will set the note's primary colour ($Color).

Note that that in its simplest form, an action() call is a quote-enclosed string. As action codes tend to use double-quoted strings, it may often be necessary to use single quotes for the outer enclosure, as in the example above.

The action function returns nothing (actually an empty string), so there is no requirement for a left-side attribute to accept any output. By comparison, the related eval(expression) function evaluates an expression and returns a value. Whereas eval() is designed to return an output, action() performs an action such as an assignment.

An action() call can be used with a do(macro) call to create a form of function as macros allow input parameters (its arguments): see do().

The action() call is particularly useful during export where it is desirable to run some action code in the context of the template during template rendering (evaluation).

Calling stamp code via action()

If a stamp's code is long/complex it can be convenient to store it in a code note. Thus if a code note 'Test-stamp' held the action code $Colour="red";, then a stamp with the code:

action($Text("Test-stamp")); 

when run would result in the stamped note(s) turning red. The example is trivial but shows the technique. Note the offset reference in the stamp to the code note is case sensitive and should use a unique $Name (or else cite the full $Path to the code note). Local attribute references, i.e. $Color or $ChildCount, are bound to the note being stamped: it is not possible to reference values in the code note using a designator.

Attribute references using action()

To build a $-prefix attribute reference in a loop, use action() instead of eval(), as described in more detail here.