I managed to get this working with a JS macro:

(function() {

exports.name = "getRelationships";

exports.params = [
  {name: "targetPerson"}
];

exports.run = function(targetPerson) {
  var relationships = this.wiki.getTiddlerText("Relationship 
Map").split("\n");
  var result = "";

  for(var i = 0; i < relationships.length; i++) {
    var current = relationships[i];
    if(current.indexOf(":") > 0 && current.indexOf("|") > 0) {
      var people = current.split("|")[0].trim().split(":");
      var note = current.split("|")[1].trim();
      if(people.includes(targetPerson)) {
        var otherPerson = people[1 - people.indexOf(targetPerson)];
        result += "[[" + otherPerson + "]] (" + note + ")\n";
      }
    }
  }

  return '"""' + result + '"""';
};

})();

My Relationship Map tiddler looks like this, with a type of text/plain:

Sarah Gallo:Bob Vurto | teammates, friends
Carl Savette:Sarah Gallo | teammates, co-leaders
Frank Gordman:Robert Daloa | best friends, teammates

And then I call it on the character page (ex: Sarah Gallo) like this:

<$macrocall $name="getRelationships" targetPerson={{!!title}}/>

Assuming the names listed in the Relationship Map are the same as the 
titles of the character tiddlers, this works great 👍 The only trade-off is 
that if I modify the Relationship Map, I have to reload the whole wiki 
(since the script has already run).


On Wednesday, February 5, 2020 at 9:57:41 PM UTC-6, Mooglegirl wrote:
>
> I have tiddlers for different characters in my story, and I want to define 
> a list of pair relationships with accompanying comments, and then generate 
> the relationships for a given character on the fly. For example, I might 
> have some hidden tiddler with something like:
>
> alice:bob (brother/sister)
> bob:carlos (friends)
> bob:darren (rivals)
> darren:alice (boyfriend/girlfriend)
>
> Then on Bob's character page, there would be an automatically generated 
> list that looks something like:
>
>    - Alice (brother/sister)
>    - Carlos (friends)
>    - Darren (rivals)
>
> How would I go about this?
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/f1b9ce93-c52d-4e99-a5ce-bc5766b2227e%40googlegroups.com.

Reply via email to