Help on a simple query about attributes containing the name of other notes

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.

Help would be greatly appreciated.

icontains exists, but icontainsAnyOf does not!

The easiest approach would be to populate separate attributes for each facet of the address. So we’d fill out the form:

Street Address:

So, Alfonse lives in the District of Illinois, the Neighborhood of Cook, and his address is 17 Cryptic Lane. In the simplest implementation, you’d fill these out manually.

Now, everyone has an explicit District, so your query is easy: $District.icontains("Gracedeen")..

What about all that extra typing? I hear you ask. That depends. You can type a lot of district names in an hour or two, but automating this might take more time than typing, at least at first.

But let’s suppose you really want to skip typing “Mishiwauka” as the district of everyone who lives in The Palace. OK — good opportunity for an agent.

Query: $Residence=="The Palace";
Action: $District |= "Mishiwauka";

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.

Hi! Thank you for the response! Regarding .icontainsAnyOf()
is what i was working from.

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)

This achieved my goal:
$Residence.icontainsAnyOf(collect(descendents("/Locations/The Empty District"),$Name)) | $Residence == "The Empty District"