Tinderbox Forum

Qualifying a Display Expression

Thanks so much for your explanation. I think I follow what you’re saying.

Anyway, I tried using the $Name + ": "+$Childcount in the Display Expression for the container. It did actually produce a number for the container – so that’s progress! But it’s showing the number of agents + containers + notes underneath that container (i.e., the children for that container).

Is it possible to just get a count of the notes and not the agents + containers underneath that container?

Thank you very much, again…

Right! $Childcount, as you know, is the number of children of the container. You want to omit the agents, and also (if I understand you) the containers.

Next step: let’s just count the children that aren’t agents. An agent has an $AgentQuery, so

collect_if(children,$AgentQuery="",$Path)

will build a list of all the children that aren’t agents. So the rule

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

will build this list of non-agents, count it, and store the number of non-agents in $MyNumber. Finally, we want to display this number with the display expression

$Name+": "+$MyNumber

Phew! Give that a spin: it’s not the whole thing, but it’s a good first step.

Thank you for your continued help (and patience!) in helping me solve this! Ok…

Yes, exactly.

Thanks! I follow the logic of this construction. To quickly back up… I’m applying this to a container (not an Agent) which contains agents and, in some cases, other containers. So, where would I copy and paste that code?

I understand that $Name+": "+$MyNumber goes into Display Expression.

Thanks again…

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

This is the rule for the container that holds notes and agents — the container that will display the count of notes inside it — excluding agents.

1 Like

Ok, I think I figured all of this out. So this…

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

…goes into the Action tab. And this…

$Name+": "+$MyNumber

…goes into the Display Expression box, correct?

Thanks!

Sorry - just following up here. Like I said, I put the code you created in the Action table, and then the other part in the Display Expression box. Turns out, there’s it’s just producing a zero – it’s not counting & displaying any of the notes.

Any other suggestions?

Thanks!

Again, it works fine for me.

So strange…

Just to be sure I’m following you…I’m putting $MyNumber=collect_if(children,$AgentQuery="",$Path).count in the Action tab, and $Name+": "+$MyNumber in the Display Expression box, correct?

Thanks.

And is $MyNumber being set to the value you expect?

Sorry - I don’t follow…

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!