Counter Action strangeness

Hi all,

The attached TB file doesn’t act as I would expect.

It has a single container note, with $MyNumber set to 1, and with the action

$KeyAttributes=$KeyAttributes+"$MyNumber"; $MyNumber=$MyNumber(parent); $MyNumber(parent)=$MyNumber(parent)+1;

When I create new notes outside of the container, and drag them into the container, the children are numbered 1, 2, 3, … as expected.

However, when I create new children from within the container, the new notes are numbered 4, 8, 12, …

Does anyone know what’s going on here?

Thanks!counter-oddity.tbx (52.8 KB)

Side note: if you are trying to add $MyNumber to $KeyAttributes, be aware the latter is a list of attribute names (“MyNumber”) and not attribute references ("$MyNumber"). The code should be:

$KeyAttributes=$KeyAttributes+"MyNumber";

If you looks at the notes added to your container, the key attributes table shows a ‘$MyNumber’. As no attribute of that name exists ($ is not a valid character in an attribute name) it looks like Tinderbox makes a best guess of a match and shows data for the attribute ‘MyNumber’.

Though Mark Anderson’s recommendation above is good, Tinderbox does automatically correct this common mistake and so it’s harmless.

The problem here is that, while Tinderbox guarantees that it will perform the OnAdd action at least once, Tinderbox is free to perform it more than once if it wants to. This simplifies all sorts of things: agents, undo/redo, and whatnot.

Suggestion: if this counter is being initialized at creation and then won’t change, test for whether you’re initialized already.

if($MyNumber==0){ $MyNumber=$MyNumber(parent);$MyNumber(parent)=$MyNumber(parent)+1;}

Suggestion 2: $SiblingOrder may give you what you’re looking for.

Makes sense — in the future I’ll write actions with this in mind. Thanks!