Tinderbox Forum

Attaching badge automatically when text added a note

I assume it must be straightforward to create an agent that will automatically set the $Badge attribute to a particular value when/if text is entered into the body a note, but I cannot work out how to do it. Equivalently, a way to add a $Badge if there is no text in the body of a note.

If an empty note is assumed to have no text then you can test for:


So you give you agent an action. Use the Action tab of the Action Inspector (which gets stored as $AgentAction). Let’s assumed we will set badge ‘label red’ for no text present and ‘label green’ for some text present. In the following I’ve split the code onto discrete lines for clarity by you can omit the line breaks is you find that easier:

   $Badge = "label red";
   $Badge = "label green";

Does that help.

1 Like

Here you go. This is one approach. You’ll need Tinderbox 8.1 v9.1.0

What’s needed.

  1. Tagger, create a Tagger, e.g. NLBadge and put in the tags, aka words, you want to flag for a badge.
  2. Action code, create action code either in the traditional approach or with a function, I used a function. See the fBadge function. Put in the conditional statements you want to use to trigger the badge.
  3. Prototype, this is not absolutely necessary, but it makes it easier, create a prototype that assigns the function in a $Rule or $Edict.

If anyone likes, I can do a video on this.

TBX L - Dynamically applying badges with Taggers and Functions.tbx (145.5 KB)

†. Admin edit: 9.1.0 as functions, as used in the emo only arrived in that version (rather than 9.0.0).

Rather than looking for $Text=="", I might check for $TextLength==0. That makes your intent more clear, and might perhaps be faster.

1 Like

Thanks to both of you. I listened to the account of functions in Mark B’s talk on version 9.1, but need to refresh my memory before I can use them. Mark A: your method works when I put his code into a stamp and apply it, which is probably all I need. I can periodically select all the notes in a container and apply the stamp. No success trying to put it into an Agent, perhaps because I am not sure what to put into the query field.

I’d also thought os $WordCount==0, but testing $Text seems more intuitive for the general audience. However I quite agree Mark B’s point re using a count rather than a string test.

AgentQuery might be

  • true if you want to do this for every note in the document (probably not what you want)
  • $Prototype=="note" if all the notes to which this applies share a prototype
  • inside(someContainer) if all the notes to which this applies are in a specific container
  • descendedFrom(someContainer) if the containers has subcontainers

Thank you very much. $Prototype=="…" does what I want nicely and it appears to have worked first time. I was being slow not to think of that before. I’ve not used it yet, but the “inside(someContainer) looks useful.” I had been trying $Container==“someContainer” but could not get it to work.

Don’t forget that for an alias in an agent, its $Container is the agent! $Container is an intrinsic attribute so not shared with the original.

You might have wanted $Container(original)==...., though I note the issue’s now resloved.

I guess it is all these complications that make TB able to do so much and to do things in so many different ways.


1 Like

Roger, @webline came up with a different (better than mine, in my opinion) implementation for this: Set the badge of a note dynamically.

Thank you both for this. It looks more complicated than a simple agent, but I guess it is more versatile.

Something I just discovered is that setting the badge can usefully be combined with “& $BadgeSize = nn” to make them more prominent.