This version is out of date, covering development from v9.5.0 to v9.7.3. 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 v9 Icon

Simulating global variables

When programming, it is sometime useful to have an arbitrary value for a something that is available anywhere in the code, regardless of the current scope; essentially a default value. Here, setting an attribute value, does the same. The exact attribute name or the location if the note storing the value isn't important, as long as having made a choice the user refers to the name/location consistently.

Since the advent of the attribute() operator in v9.5.0+, another method is simply to make a user attribute per desired global variable and set its default, altering if needs be via attribute("AttributeName")["default"].

More common practice is designate a single note, often at the outline root as a configuration or 'config' note and store/alter global values there. By the same token, it is possible to use one attribute for several globals using a different note, but the same attribute, to hold each value.

There is no correct way. With the advent of attribute() adding a suitably named/typed attribute is the cleanest method as there are not locations to remember for getting/setting the attribute. In contrast, if globals might need to be copied from one TBX document to another, e.g. to set up a particular workflow, them a config note(s) is possibly an easier approach. This aspect of Tinderbox is still evolving so what is best/safest/least effort may change over time.