This isn’t correct, though it’s often how |=
behaves. $Attribute |= somevalue
will assign somevalue
to $Attribute
only when $Attribute
’s current value evaluates to false
in a boolean context. Whether that value is a default value or not makes no difference.
As a quick counterexample, open a new Tinderbox document, and make a stamp with the action $Color |= "red"
. Applying this stamp to a new note will have no effect, even though the new note’s Color
attribute still has its default value. This is because the default Color
attribute for a new Tinderbox document is a non-empty string ("warm dark gray"
), which evaluates to true
in a boolean context.
By contrast, if you set a note’s Color
to 0 (or to no value), and then apply the stamp, the note’s Color
will then be set to "red"
.
Many attributes have a default value of the null value for their data type (0 for numbers, the empty string for strings, never for dates, etc.). These null values evaluate to false
in a boolean context, so for these attributes, |=
will act mostly as you’ve described. But for attributes such as Color
, Width
, and Container
, which have non-false default values, |=
will have no effect. If you really want to only override a default value, you have to use something like if(!hasLocalValue("Attribute")) {$Attribute = somevalue}
.
As an aside, the in aTbRef reads as incorrect to me. Specifically it states
In practical terms this means the left side, usually an attribute - is set to the right side value only if it is not already set at note level, i.e. its current value is either:
- The default for that attribute data type (for a string attribute “”, for a number 0, for a date ‘never’, etc.)
- A prototype-inherited value (which in effect is simply altering the default value)
The first bullet point is correct; as I understand it, the second one is not.
Furthermore, this example is given:
Consider three different notes and their $Color. The first is new and uncustomised, $Color is the default. The second has a prototype setting $Color to “green”. The third has been manually set to “bright blue” by the user. If this action is applied to all three notes:
$Color |= "bright red"
then two of the three notes will recolour. The first is has a default $Color so changes. The second note is green, but only because that is the default inherited via its prototype; it too, is re-coloured as it currently uses a default value. The third note is bright blue and this was expressly set at note level. So, as the latter does not use a default value, it remains bright blue.
In fact, the action $Color |= "bright red"
will have no effect on any of the notes, since in all three cases $Color
is a non-false value. See the attached .tbx file, and note that the stamp with action $Color |= "red"
has no effect on any of the notes.
or-equals-example.tbx (53.3 KB)