This version is out of date, covering development from v5.0.0 to v5.12.2. It is maintained here only for inbound reference links from elsewhere.

Jump to the current version of aTbRef.

Tinderbox Icon

Delaying code execution in Prototypes

When using pre-planned structural prototypes, i.e. those stored apart from actual content and with no function other than as a prototype for content, consideration should be given to whether action code such as found in in Action-type attributes is run in the prototype itself, or should be suppressed there and only run in a note inheriting from the prototype. This scenario affects code placed in the Action-type attributes (e.g. via their create/rename dialog boxes):

In some cases it is desirable to delay code execution as the code is written with the intention of running in an inherited context, using actual data from the inheriting note. It is also desirable to delay where there is a need to run code once only but again, within an inherited note's context.

From v5.8.0, two of the above attributes have special system attributes to suppress prototype execution. $DisplayExpressionDisabled and $RuleDisabled, then set to true, suppress the running of the note's $DisplayExpression or $Rule. In pre-v5.8.0 versions, or where using other Action-type attributes, employ the more method outlined below.

Where no disablement attribute exists, consider wrapping the code in a conditional test, for example:

if(!$IsPrototype){$AgentQuery="Topics("+$Name+")";} 

The above ensures that, in a prototype agent, the agent's query isn't set within the prototype whereas in all agents inheriting from the prototype the query will be set. The need for a wrapping if() conditional test becomes clearer with this rule:

if(!$IsPrototype){$AgentQuery="Topics("+$Name+")";$Rule="";} 

Without the if() test, the latter rule would run and delete itself within the prototype and never set anything in the inheriting agents.

Note too, that if using self-deleting rules via a prototype the act of clearing the rule breaks inheritance for the $Rule attribute.


Possible relevant notes (via "Similar Notes" feature):


A Tinderbox Reference File : Actions & Rules : Delaying code execution in Prototypes