Qualifying a Display Expression

The purpose of the action

$MyNumber=collect_if(children,$AgentQuery=="",$Path).count 

is to set $MyNumber of your container to the count of its children that are not agents. If you’ve done this correctly, then $MyNumber will be set to this value.

Is it?

So, I need to actually insert a number in the code – i.e., the of agents under the container – for the code to work? If I’ve got that right, where would I put that number? Sorry for not grasping this…

No!

You’re entering a RULE in the container. A rule is an action that Tinderbox performs from time to time — perhaps every 5 seconds. In this case, the rule is:

$MyNumber=collect_if(children,$AgentQuery=="",$Path).count 

Translated into English, this rule is something like:

Look at each of the children of this note. If it’s an agent, ignore it. Otherwise, increase the count by one. When you’re done, save the result in $MyNumber.

So, every few seconds, Tinderbox will count up the number of non-agents in your container and save that count as the value of $MyNumber for that container.

I’m asking, “Is the value of $MyNumber for the container what you’d expect?” I mean, if you have (say) 17 notes and 3 agents, then:

  • if $MyNumber was 17, you’d be happy!
  • if $MyNumber was 18, you’d likely say, “maybe I counted wrong.”
  • if $MyNumber was 20, you’d say, “maybe I’m not skipping the agents.”
  • if $MyNumber was 0, you’d say, “maybe I mistyped the rule, or entered an OnAdd action when I mean to enter the rule, or something like that.”
  • if $MyNumber was 742, you’d say, “this can’t be right; maybe I’m looking in the wrong place.”

Ok, sorry.

Well, my number is 0 for every container that has that code.

I’ve just copied and pasted that code in the Action tab, and included the code other for Display Expressions.

I haven’t included any add-ons or anything else. Sorry…I’m just trying to solve it, and thanks again for your help.

This is what it looks like on my end…

Screen Shot 2021-05-10 at 5.18.22 PM Screen Shot 2021-05-10 at 5.18.13 PM

HI @jprint714, personally I use a different approach to accomplish what you’re trying to do. Please check out the video I just made for you:

1 Like

It looks like you’re entering an OnAdd action — an action performed on a note when it’s added to the container. When performing an OnAdd action, this note is the note being added; if it has no children, $MyNumber will be zero.

What you want is a Rule: an action performed on a note or container every few seconds. When the rule is run, this note is the action with the rule.

Wow. Thank you so much, @satikusala! This is amazing - and so much more than I was expecting! I confess I’m still mystified by all code (I’m also dyslexic, so it’s esp. tough for me), but this video certainly helps a great deal…

I followed your instructions, pausing as needed to follow along. The action code worked for the first part of what you set up with child count. But I’m sorry to say that it did not work with descendants. I think I might be off somewhere in the code or setup, but it’s hard for me to tell what went wrong and where (e.g., if I’m mixing up periods and commas in your code). Anyway, here’s the set up for the Quickstamp / DisplayExpresion part of the set up…

Screen Shot 2021-05-11 at 10.37.54 AM

…and here’s the code for the Edict section…

Screen Shot 2021-05-11 at 10.41.12 AM

BTW, I just caught @eastgate’s comment, and tried removing it from Edict, pasting it in Rule – and then removed and re-attached the prototype, etc. I’m sorry, but it didn’t generate a descendent count.

Let me know what else you’d suggest, and than you all – again – for your incredible help! I feel like I’m getting there… Thanks!

Hey @jprint714, I’m so glad you’re happy!!! I empathize with the dyslexic comment, I totally get it. Not to worry, it is hard for us all.

Quick question, are you trying to replicate this process in your own file? Looks like it given the naming of your screenshot.

First off, I assume you’ve already created the $DisplayExpressCache user attribute, yes?

Secondly, I can’t tell from the screenshot, are you updating your prototype or a note folder? From what I can tell in your first screenshot it looks like you’re updating a note folder and not the prototype. I see this because it says “assigned to this note”. So, that tells me that you’ve edited a note and the inheritance to the prototype might have been severed (which happens by design). Not to worry.

What you want to do is re-connect the inheritance to the prototype.

In the Quickstamp, do a search for Rule or Edit, I believe that is where you put the action code. You’ll want to reconnect the Rule’s inheritance to the prototype. To do this you’ll click the button right under default an this will reset the inheritance. If the code is correct you should be good to go.

Public Service Announcement (PSA): Everything I just said above can be super confusing as there are TONs of new concepts being thrown your way–code, prototype, attribute, inheritance, optimization–with little background or setup. It is natural to say “I don’t have a F**k’ng clue what you’re talking about.” :wink: This awareness is the first step to success. The next step is our working together so that not only do you have a clue but your empowered. We can do this. You’ll get there.

So, with this PSA out there, let me do this. You can try the quickstamp approach I note above, but if you ca wait until the end of the day I’ll create a video that explains it.

1 Like

Thanks so much…really appreciate all of that, though it sure seems like this is much easier for some than for others! Anyway, in answer to your questions…

Correct - through the process you outlined in your web video.

I’m trying to reproduce what you’ve done in an existing Tinderbox file. In that file, I’ve already created a Prototype folder and a prototype. I created the “Folder” prototype in that same Prototype folder, and set it up by following your steps.

Yes, I’m applying the “Folder” add-on prototype to a note folder.

Got a little lost here in what you’re asking for and suggesting I do next… But quickly, two questions…

  • Have I properly produced the code you provided? I ask because it’s hard to see some of the punctuation in your web video. Here’s what I typed…

    $MyNumber=collect_if(descendants,$Prototype!="Folder",$Name).count; $DisplayExpressionCache=$Name+" ["+$ChildCount+"]";

  • Also, should this go into the Edict or Rule box?

Thanks!

Close…
In this case you’ll want to replace $ChildCount with $MyNumber, as $MyNumber now holds the count without folders being counted, whereas $ChildCount counts all Children.

So, in this context you’ll say:

$MyNumber=collect_if(descendants,$Prototype!="Folder",$Name).count;
$DisplayExpressionCache=$Name+" ["+$MyNumber+"]";

I just realized there were some smart quotes in there, and that might account for the problem. Ok, so now the code is:

$MyNumber=collect_if(descendants,$Prototype!="Folder",$Name).count;
$DisplayExpressionCache=$Name+" ["+$MyNumber+"]";

Does this belong in the Rules or Edict box?

Strangely, I removed the “Folder” prototype add-on from the notes container, but the folder badge remains intact. Anyway, I reapplied the “Folder” prototype add-on with the corrected code, but it’s still not generating any number. Any other suggestions?

Thanks!

Looks good.

Action code can be in a Rule or an Edict. Rules run continuously, Edicts run periodically, that is the only difference. I prefer Display Expressions to be in Edicts because I use a lot of them and I don’t need the instantaneous update.

I don’t recall there being an $OnAdd for the prototypes, but that does no matter. An $OnAdd has nothing to do with a badge. Removing that will not remove the badge. Now, if you change a note’s prototype that could affect the badge. More on this later.

No other changes. If it is still not working, I bet you have a severed inheritance issue. As noted, I’ll record a training on this later.

I think I follow you, and will try using the prototype with a fresh data set. I should hasten to add that I’m working in Outline view, not maps — and that’s why I’m applying the Folder prototype to note containers as an add-on. FWIW…

Thanks again!

Important to note, views are just views, different lens for analyzing and working with your notes. Views have no effect on action code. Action code works the same way in map view, or outline view. If you have an $OnAdd function running, it will apply just the same whether or not you’re in map view or outline view.

1 Like

Thanks. I might be using the wrong phrase to describe what I’m trying to do.

Here’s a dummy set up…


…and the “add on” action I was referencing, in which I’m right-clicking the Note Container folder, and then selection the Folder prototype…

Screen Shot 2021-05-12 at 9.19.50 AM

Ok, I see the problem. :slight_smile:

Look at your action code, it says $Prototype!="Folder".

Look at the name of your prototype “Folder prototype”. Your action code is looking for the prototype “Folder”. This does not exist. What exists is “Folder prototype”. To fix this, change the spelling of “Folder prototype” to “Folder”.

Remember, note names are not unique, i.e. you can have multiple notes named “Folder”. A best practice is to ensure your prototypes always have a unique name. I and others accomplish this by appending a lowercase “p” to prototype names, e.g. “pFolder”. So, to modify the above, I would change your prototype name to “pFolder” and your action code to reference “pFolder”.

1 Like

Thanks so much. I actually did exactly what you suggested in the original Tbx file, but not in in the dummy. So, I doubt that’s the actual problem in this case. I’ll try setting it all up again in a clean file, and will report back… Thanks again.

1 Like

Ok, I’ve good news and bad news…

I’ve changed the name of the prototype to “pFolderCount,” and applied it to a folder in a fresh dataset.

The good news is that prototype does produce a number next to the folder.

The bad news is that it’s also counting the agents in the folders (i.e., what we called the “note container” – which really contains agents, and notes that fall under those agents), so the number counts are inaccurate.

How would you suggest I fix this?

Thanks!

First, good job on your progress.

Can you do two things?

  1. Give me a screenshot of your outline view
  2. Give me a screenshot of your pFoldercount edict

It will be hard to debug without seeing what’s going on.