Ugh okay I’ve been trying to do this on my own and I know it must be simple but I can’t figure it out and I’ve spent hours now.
I have my Locations container. In Locations, I place Districts. In each District there are Neighborhoods. Possibly eventually in Neighborhoods will be Notable Addresses.
Each character in my world lives in a Neighborhood or District, recorded in $Residence. I want to build Agents (or an Edict, maybe?) that tells me all the characters who live in a District, including those who live in Neighborhoods contained within that District.
In simple text, I want to see every character whose $Residence matches either Gracedeen, or the descendents of Gracedeen. I’ve been messing around with descendedFrom and icontains and I simply can’t get it to work.
$Residence.icontainsAnyOf(descendedFrom("Gracedeen")) is what isn’t working and I have no idea why. I know I’m somehow not doing the right thing with descendedFrom because icontains variants work without that. And I’ve used descendedFrom successfully to gather up the descendents of Gracedeen itself within the agent. But what I want are the notes that have Residence set to one of those descendents.
The odd symbol “|=” is pronounced “or-equal” and means: “do this assignment if the District isn’t already set.” That lets you have a character whose $Residence is “The Palace” but who doesn’t belong to Mishiwauka for some other reason.
Another approach would look for the unique note “The Palace” descended from “Locations”. You could look up the district by getting the name of the parent note.
And yeah, I could just set full addresses, it wouldn’t be that hard, but I thought I might avoid User Attribute proliferation by taking advantage of the descendency, as you indicate in your final suggestion.
My main problem is that I can find the Neighborhoods in a District by looking at the descendedFrom, but I cannot figure out how to them compare that list of Neighborhoods to the character’s Residence attribute. Maybe this is just best done with temporary variable storage? A multi-step search? I’ve been uncertain about to conceptualize and implement that though.
Thinking aloud here, in English:
First, find all the descendents of the container Gracedeen.
Second, look at all of the $Residence attributes and return the ones who have a $Residence that matches an element of the list created in the first step.
I’ve poked at this without using temporary storage but I can’t even get the list of descendents stored in $MySet (on the Agent or the test note), so I’m clearly doing something wrong there.
Oh, of course! Silly me. The problem in your expression was (I think) that decendants() returns a list of paths, and you want a list of names. You could collect(descendants,$Name) to build the list you wanted.
I can’t even get the list of descendents stored in $MySet
How about $MySet=collect(descendants,$Path)