Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Questions and Answers >> Passing string to descendedFrom() in $AgentQuery
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1460587057

Message started by Scott Heftler on Apr 13th, 2016, 6:37pm

Title: Passing string to descendedFrom() in $AgentQuery
Post by Scott Heftler on Apr 13th, 2016, 6:37pm

I have an interactive agent that I want to be easily modifiable by the user.  The interaction: the user gets to pick from strings in a pre-populated dropdown inside the Key Attributes area of the Text View.  The normal $AgentQuery is:

descendedFrom("some_container") & $Prototype==refill_note

If I want some_container to be set by the user via $StringPicker, you'd think that might be something like:

descendedFrom(eval($StringPicker)) & $Prototype==refill_note

But of course it does not.

I also tried constructing a string inside the agent's $Text

"descendedFrom(" + $StringPicker(agent) + ") & $Prototype==refill_note"

and then using this as my $AgentQuery

eval($Text(agent))

But of course it fails as well.

Any possibilities?

Title: Re: Passing string to descendedFrom() in $AgentQuery
Post by Mark Anderson on Apr 13th, 2016, 7:46pm

[TL;DR - the answer is at the end, but I thought it useful to explain why some obvious alternate solutions don't work]

So the source of the variable is the value of the agent's $StringPicker attribute? It feels like it should be:

descendedFrom($StringPicker(agent)) & $Prototype==refill_note

That doesn't work and the reason is the 'agent' designator is to allow children of an agent, i.e. its aliases, to reference attribute values in the aliases' parent agent. So what about 'this'?

descendedFrom($StringPicker(this)) & $Prototype==refill_note

Wrong again, because, inside a query term, 'this' is the note being tested, - note the one doing the testing (here that's the agent). The answer is the someone oddly named 'that' designator which exists to solve just this sort of problem for queries. The latter might be an agent or if() condition but more often is a find() nested in some piece of action code. This works for me:

descendedFrom($StringPicker(that)) & $Prototype==refill_note

Title: Re: Passing string to descendedFrom() in $AgentQuery
Post by Scott Heftler on Apr 15th, 2016, 1:19am

Hello Mark and thanks for your instructive answer.  I've tried using

descendedFrom($StringPicker(that))

to no avail.  The agent collects nothing.

Not sure what's going on.

Title: Re: Passing string to descendedFrom() in $AgentQuery
Post by Mark Anderson on Apr 15th, 2016, 9:47am

That's odd. What worked yesterday - in a file I didn't keep (as it worked!) doesn't work in the doc you kindly sent me.  This is a gnarly confection of what designators can be used in an agent query and the degree to which inside() and descendedFrom() allow use of evaluated parameter. I suggest sending the file to support (info@eastgate.com).

In part I think the problem is the edge case during testing where one may have several agents running discrete but similar queries. It ought not to matter if we just want to know if the original of X is a child of Y. But if the operators start allowing aliases into the evaluation, it works when it works but not when it doesn't.

For once, I'm completely stumped after a couple of hours trying to make this work. I'd agree it's a very simple test - in principle.

~~~
If we can establish better how these operators work, I will of course write it up

Title: Re: Passing string to descendedFrom() in $AgentQuery
Post by Mark Bernstein on Apr 15th, 2016, 9:49am

You aren't giving us enough information for us -- or anyone -- to help you.

Here's how to address puzzles like this.

a) Start with an agent that's so simple, it couldn't possibly fail.

    descendedFrom(/path/to/theAgent)

Make the agent. Make sure it does what you expect.

b) Now, we want to replace the explicit path with an attribute reference. Where are we going to put the value?  It could be in several places

    1) The agent: descendedFrom($StringPicker(agent))
    2) The note the agent is checking: descendedFrom($StringPicker)
    3) Some other place (descendedFrom($StringPicker(/configuration))

I just tested #1, which I think is what you intend, and it does work as expected.


Title: Re: Passing string to descendedFrom() in $AgentQuery
Post by Scott Heftler on Apr 15th, 2016, 4:27pm

Sorry about the lack of info: I'm running TB6 6.5 (b198) on a 2011 MBP OS 10.11.4.

Yesterday I tried descendedFrom($StringPicker(agent)), which did not work, along with the silly/long-shot queries I mentioned in the original post.  Then I tried descendedFrom($StringPicker(that)), which also didn't work.

Today, inexplicably, the query expression that failed yesterday is now working.  Very glad and thanks to you both for your help.

Title: Re: Passing string to descendedFrom() in $AgentQuery
Post by Mark Bernstein on Apr 15th, 2016, 5:04pm

It's fairly easy to foul things up with a typo, or unmatched parenthesis. That's why the step-by-step gradualism helps.

When it can't possibly be wrong, well, either it works or it clearly doesn't!

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.