Trying to substract sets of text

Congratulations for the new forum. I am getting back to Tinderbox with the new version, trying to build some automation for student records. As usual, I did achieve quite a lot more than I thought possible, but have ended up struggling to get the last piece of functionality I need in order to actually use it. I presume Tinderbox is capable of performing the tasks I am seeking, so I write in the hope that the mistakes I have surely ended up making are easy to correct.

Although the code below might be inefficient, it does seem to work properly: When a value is added to the completed assignments attribute of a student record, an agent adds to its text that of the corresponding assignment note.

$Text="Quarter 1 " + collect_if($Assignment,$Quarter=="1",$Text).sort($Name($OutlineOrder)).format("\n")  + "
"Quarter 2 " + collect_if($Assignment,$Quarter=="2",$Text).sort($Name($OutlineOrder)).format("\n")  + "
"Quarter 3 " + 
collect_if($Assignment,$Quarter=="3",$Text).sort($Name($OutlineOrder)).format("\n")  + "

My problem is that I would like the same full text information to appear about the uncomplete assignments for each quarter. I have tried to get all values (at least the ones that have been used) for the assignments attribute in the document, performing on their text the same sorting and formatting as above. My intention was to substruct each of the above sets from all values in the document for the same quarter that do not intersect. And it doesn’t seem to be a good approach.

Try to understand the scenario, two quick questions notes. Firstly, your code example ends each line of code with an unclosed string, e.g.:

...format("\n")  + "
"Quarter 2 " + collect...

How is the first line above supposed to end? If want a line break, do it like so:

...format("\n")  + "\n" +
"Quarter 2 " + collect...

Secondly, how are you testing for completion of an assignment? What data type is $Assignment? Is there a prototype or a container that encompasses all assignments?

Thank you for your patience. I introduced those mistakes when replacing some non-English words for posting here. Without them, that part of the code works, as far as I can tell, correctly.

$Assignment is of set data type. There is a prototye that encompasses all assignments and, unnecessary as it may be, so far they are also placed in the same container. This is probably why $OutlineOrder seems to work correctly -if set to sort names, not the text attribute I want to collect.

Uncompleted assignments for each student are the many that have not been added to his own note’s $Assignment. This is why I later tried to store one of the above in $MySet, and later attempted to substract: collect_if(all, $Assignment & $Quarter=="1", $Text).sort($Name($OutlineOrder)).format("\n") - $MySet

OK, you don’t note your prototype so I’ll use pAssignment in the code below. This finds all assignment- prototyped notes. Query:

$Prototype=="pAssignment"

This finds all assignment prototyped notes without any $Assignment data. Query:

$Prototype=="pAssignment" & $Assignment==""

The agent’s sort, set via the Action Inspector’s Sort tab is by ‘OutlineOrder’ and by ‘original note’, which sorts the aliases on the $OutlineOrder of the original note of the alias.

Now the action to place the code is the agent’s text is:

$Text = (collect(children,$Text)).format("\n")

If you have more detailed questions, it would help us help if you uploaded a small specimen TBX so we don’t have to guess un-described logic and have a common frame of reference for testing.

I attach the file. I have managed now for it to substract from pending assignments in each student’s note when new assignments are added to him. It also fills the student’s text with text from the assignments. Your reply set me on the right track. Thank you.

Still, .format("\n") doesn’t work and the document seems slow, so there are probably some conflicting agents or rules.
StudentAssignments.tbx (113.9 KB)

Glad to hear you progress and thanks you for taking the time to share test files. The issue with the list formatting is because you’ve added erroneous $Text references. I believe the effect you want in the student note is like this:

tbx%202019-05-13%2007-26-41

I added an extra line-break to make the headings clearer. The code needs in note ‘StudentAgentActionCode’ to make the above is this:

$PendingAssignment = $Assignment("/AssignmentAgent")-$Assignment;
$Text = "Assignments: " + "\n" + $Assignment.format("\n")+ "\n\n" +
"Pending assignments: " + "\n" + $PendingAssignment.format("\n");

If you don’t want the extra line break, change the code "\n\n" to "\n". It only occurs once so should be easy to find.

I commend the use of a Code prototype for 'StudentAgentActionCode, though I’d suggest using that prototype’s choice of a mono-space font. If pasting into a new not (without $Text) that uses the prototype use ‘Paste and Match Style’ (Cmd+Opt+Shift+V) to add text, e.g code from elsewhere.

If you apply the Code prototype to a note that already has $Text content, select the note’s $Text and use Format menu -> Style -> Standard Font (Cmd+Opt+Ctrl+T) to re-apply the prototype’s monospace font. The latter makes it easier to see things like (the amount of) whitespace and whether you’ve got the right type of quotes (string in action code must use straight and not curly quote characters)