Problem with $DisplayExpression run by an edict

I nicked a trick from Michael Becker’s @satikusala recent video which has an edict to automatically sum up the run time of scenes in a group and display it as a $DisplayExpression. However, when I run it in my TBX file, it does not display correctly, and I have no idea why.

What I am using this for is a course outline where I deliver lectures taped on video (b/c of the pandemic), and I want to keep track of the duration. So every video has a $Dauer (= duration in German) attribute, and the lecture (the $Name of which is the date on which it is uploaded) has an attribute $GesamtDauer (= overall duration) that sums up the duration of the three videos I create each week.

I run an edict which is taken verbatim from Michael’s code (except the changed variable names):
$GesamtDauer=sum(children,$Dauer);
$DisplayExpression=$Name+" - Gesamtdauer: "+$GesamtDauer;

However, in Outline view what I get is an incomplete version of the result:
Bildschirmfoto 2021-04-19 um 16.49.35
although both the $GesamtDauer attribute and the $DisplayExpression attribute are correctly set:
Bildschirmfoto 2021-04-19 um 16.49.46

Basically, the $DisplayExpression cuts out a part, shortens its content to “19.04.2021-17” (instead of “19.04.2021 - Gesamtdauer: 57:17”) and displays only the last two figures rather than the full value of the attribute.

Any idea why this could be? I have no idea.
Thanks for any help!

The DisplayExpression is a formula — a recipe for deciding what to display. For example, one display expression might be

$Name+":"+$Beginn

This would tell Tinderbox to, when it needs to display this note, call it by its name, followed by a colon, and then by the value of $Beginn.

Your DisplayExpression is 19.04.2021 - Gesamtdauer.... Tinderbox tries to parse this as an formula. It seems “19.04” — that looks like a perfectly reasonable number. So it’s going to be very confused!

What you want to do is to save the string you’re saving in $DisplayExpression in a string attribute — perhaps $MyString — and then for your display expression simple write

$MyString

I’m afraid that’s a misunderstanding. The edict has a formula, namely

$DisplayExpression=$Name+" - Gesamtdauer: "+$GesamtDauer;

(Sorry I did not format this correctly in my original post.)

I merely had it displayed in the Displayed Attributes so I could check it was correct - and it is. So I do not quite understand what I did wrong. Should I not have the $DisplayExpression displayed attribute displayed as that confuses TBX?

That won’t work as you’re asking to set the value of $DisplayExpression to the evaluation of the right side of the equals sign, when you mean to pass that code as a string to be evaluated when $DisplayName is computed from the code in $DisplayExpression

So, what you need is:

$DisplayExpression='$Name+" - $Name+" - Gesamtdauer: "+$GesamtDauer: "+$GesamtDauer';

Note the extra single quotes around the right side. Now, the contents of $DisplayExpression is

$Name+" - Gesamtdauer: "+$GesamtDauer

Without those extra quotes, Tinderbox was trying to evaluate $Name minus the string "Gesamtdauer: " plus $GesamtDauer.

Remember, when setting $DisplayExpression, indeed any Action-type attribute’s value via action code, you must enclose the whole code section in quotes. If the code already uses double-quotes, use an other set of single quotes.

Many thanks - that solves the problem! And I hope I’ll remember the special status of $DisplayExpression better in the future; I did know it once.
By the way: the first quoted line of your code doubles several entries. Just so noone reading this later is confused…

2 Likes

Hi, after a couple of years, again a problem with $DisplayExpression run by an Edict, and another appeal for ideas and support…

I have a Note which has a Displayed Attribute $LVTyp (this is part of my teaching system, and it carries the type of course, i.e. a seminar, a course of lecture and the like.
The note’s $Name is the title of the course, and I want $DisplayExpression to give me the type and the title - like in “Seminar Comparative Politics”, with the first being the $LVTyp and the last two words being the $Name.

However, the following Edict does not produce what I want:

$DisplayExpression='$LVTyp + " " + $Name';

With $LVTyp being “Seminar” and the $Name being “Comparative Politics”, I would expect $DisplayExpression to give me what I described above. Instead what I get is
“Comparative Politics;Seminar” (without the quotes).

Having fiddled with this and also tried it in a new TBX file, I have no more ideas. Surely the solution is very simple, but I just don’t understand what I am doing wrong…

Thanks for any help!

P.S. $LVTyp is of type set in case that is of interest.

Edit: Apparently the type is of interest! If I change it to string, the problem goes away. Which prompts the question: why does the type here make such a difference?

Your P.S. and P.P.S. pointed to the cause. The contents of $DisplayExpression, is action code, and so when we set:

$DisplayExpression = '$LVTyp + " " + $Name';

The stored value of $DisplayExpression is:

$LVTyp + " " + $Name

or in type terms (for the given attributes:

Set-type + space + String-type

Adding something to a list (e.g. a set) adds to the list. As new list value strings are trimmed, the first item added—a single space—trims to nothing and nothing gets added. The next item is the $Name string and out result is now:

[Original Set value;Name string]

If, despite the attribute type, $LVTyp in this context will always only contain only a single value we can use the first list (Set) item’s value so that we are space-concatenating two Strings. Thus:

Set's-first-item + space + String

results in

String + space + String

So:

$DisplayExpression = '$LVTyp.at(0) + " " + $Name';

If $LVTyp will contain more than one value, e.g. Seminar ;Tutorial then a safer code approach might be:

$DisplayExpression = '$LVTyp.format(", ") + ": " + $Name';

which gives a $DisplayName—the displayed title—of “Seminar, Tutorial: Comparative Politics”. The comma+space join the Set’s lists, add a colon+space buffer and then the note’s title String.


This begs the questions, why is $LVTyp a Set if it only stores one value. I suspect what’s happening is that in different contexts the attribute is doing two discrete tasks. One is to store the (single) value per subject, i.e. the example above. Then, in an agent or the above note’s container the same attribute is being used to hold all the subordinate tasks.

From scenarios like above, if this occurs I tend to make two separate attributes with similar names. So we might have a String LVTyp and a Set LVTypes—the plural in the latter is deliberate as it implies it is a multi-value type (i.e. can hold one or more values).

Another possible cause of using the set is to make it easier to pick an existing value from a pop-up list in a Displayed Attributes table, but these exist for String, List and Set types. You can also set up suggested values. These are available in the pick-list but don’t count as a used value until at least one note holds that suggested value.

1 Like

Many thanks for your patience in explaining this, Mark! Much appreciated.
The main reason for choosing set type is that it automatically de-duplicates entries. While I discovered that I can also choose from a drop down menu if the type is string, set seems to me to be more correct (slightly nerdy, I assume…).
So explicit thanks for also providing a way out with the .at(0) addition to the action code - I have implemented that and returned $LVTyp to is set existence :wink:

1 Like

No worries, it was a nice little start-of-day riddle. :slight_smile: