Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Passing string to descendedFrom() in $AgentQuery (Read 1096 times)
Scott Heftler
Full Member
*
Offline



Posts: 33

Passing string to descendedFrom() in $AgentQuery
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?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Passing string to descendedFrom() in $AgentQuery
Reply #1 - 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
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Scott Heftler
Full Member
*
Offline



Posts: 33

Re: Passing string to descendedFrom() in $AgentQuery
Reply #2 - 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.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Passing string to descendedFrom() in $AgentQuery
Reply #3 - 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.

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
Back to top
 
« Last Edit: Apr 15th, 2016, 9:47am by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Passing string to descendedFrom() in $AgentQuery
Reply #4 - 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.

Back to top
 
 
WWW   IP Logged
Scott Heftler
Full Member
*
Offline



Posts: 33

Re: Passing string to descendedFrom() in $AgentQuery
Reply #5 - 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.
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Passing string to descendedFrom() in $AgentQuery
Reply #6 - 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!
Back to top
 
 
WWW   IP Logged
Pages: 1
Send Topic Print