Important note: all examples follow aTbRef naming conventions.
Functions can be defined in any action code space:
- Library notes (notes under
/Hints/Library
). Do not store code in the Library container note itself - Action attributes: Rule, Edict, AgentAction, OnAdd, OnRemove, etc. (see all).
- Stamps (note or Inspector).
- A note with the 'Action' prototype set (edge case, arbitrary use is not generally recommended unless the above don't suffice)
Given their re-useable nature, Library notes are probably the most logical place for storage, but is not a requirement. But a strong recommendation as a first a choice.
Regardless of where stored, any user function, defined in any valid location (see above) in the current document, can be called from any action code in that document.
Therefore, for novice users, the last option—a Library note (first in list above), is the best place to start.
New users might choose to add only only function per note until comfortable with the process, noting the section below on naming library notes and note's $Name vs function name(s) in their $Text.
What goes in a Library note
A library note can contain:
- one, or more, discrete functions.
- other arbitrary action code expressions, e.g. rules, agent actions.
In combination, the above two an allow Library notes to act as a way to store and share 'libraries' of code between different Tinderbox documents and/or users.
If storing non-function action code such as rules in a Library note, it may be useful to enclose such code in an inert function, thus:
function fDoNotUse(){..code ...}
i.e. one with no inputs and no return and with a name unlikely to be called in code.
Naming Library notes
The titles ($Name) of Library notes are not used to call a function, and should not be the actual name of a function so should simply be indicative of purpose. Do not use the exact name of a user-defined function lest it confuse Tinderbox, i.e. $Name should not match a function's name.
Thus, if a Library note contains a single user function 'fDoMyTask()', do not call the note "fDoTask()". Better would be "Do MyTask" or "function fDoMyTask".
Be aware how this differs from stamp notes, where the note's $Name is the name of the stamp is called from code
Next: Naming functions