Help needed: precalculate a counter in a dropdown

Greetings people
Long time reader, first time poster
Since i heard of Tiddlywiki i use it for a lot of things either work or hobby stuff. A good chunk of the wikis i have made are roleplayig related, to keep track of stuff, rules and character sheets. After a pretty successful Pathfinder 2 wiki, im working in a variation of the GUMSHOE system.

I came up with a way to compare characters score in different skills and show it side by side; you select a skill from a dropdown and it list the characters that have a value in the corresponding field along with such score. No problem there.
The issue comes from the fact that there are several skills that noone have score in and the only way to find out is selecting it and see in despair how nothing shows up. Then i thought “What if i could add a counter?” and came up with this

<$select field="hab">
  <$list filter="[tag[Habilidad]]">
   <$set name="punt" value={{{[[Habs]getindex{!!hab}]}}}>
   <option value=<<currentTiddler>>><$view field='title'/> <$count filter="[tag[Agente]has<punt>]"/> </option>
   </$set>
 </$list>
</$select><br>
<$macrocall $name="generaLite" hab={{!!hab}}/>

where Habs is a dictionary that “translates” the skill name to the field in the character’s tiddler (tagged Agente) that store the value.
generaLite is the macro that actually paints the results, but i don’t think is relevant right now.

The problem is that it shows the current skill value for every option until it changes and then it recalculates. I tried to move the counter but it make sense you cannot calculate based on a value you didn’t choose yet.
Is there an easy (i know nothing about Javascript, for example) way to make the values to show up in the dropdown?

I thought of making a field in each skill tiddler that stores the value of current characters that have any score in that skill, but i’m not sure how it could auto-refresh.

Than you in advance for any insight.

I figured it out, thank you.
If someone is interested the solution was

<$select field="hab">
<$list filter="[tag[Habilidad]]">
<$let set hab=<<currentTiddler>> punt={{{[[Habs]getindex<currentTiddler>]}}} num={{{ [tag[Agente]has<punt>count[]] }}}>
<option value=<<currentTiddler>>><<currentTiddler>>  <<num>></option>
</$let>
</$list>
</$select><br>
<$macrocall $name="generaLite" hab={{!!hab}}/>

Here’s a little “cleanup” to your new code:

<$select field="hab">
   <$list filter="[tag[Habilidad]]">
      <$let punt={{{ [[Habs]getindex<currentTiddler>] }}} num={{{ [tag[Agente]has<punt>count[]] }}}>
      <option value=<<currentTiddler>>><<currentTiddler>> <<num>></option>
      </$let>
   </$list>
</$select><br>
<$macrocall $name="generaLite" hab={{!!hab}}/>

Notes:

  • Removed set and hab=<<currentTiddler>> from the $let widget:
    • set by itself does nothing
    • you never reference hab after defining it

enjoy,
-e

1 Like