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
shadow distance conditional on key docs (Read 5768 times)
Ben Worthington
Full Member
*
Offline



Posts: 110

shadow distance conditional on key docs
Jan 28th, 2009, 3:16pm
 
hello all - i have notes which i label 'keyfef' (this is a boolean attribute) if I am likely to refer to them lots. keyrefs and other (non key) notes are stored together inside various containers. i want the containers to stand out (say by increasing shadow distance) in the map view if they have, say, more than 5 keyrefs.

How would i do this?

Many thanks,

Ben
Back to top
 
« Last Edit: Jan 28th, 2009, 3:17pm by Ben Worthington »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re:  shadow distance conditional on key docs
Reply #1 - Jan 28th, 2009, 3:22pm
 
AgentQuery: keyref=true&ChildCount>5
AgentAction: ShadowDistance=10

If a note is a keyref and it's child count exceeds 5, then the shadow distance will be set at 10 (default = 5).
Back to top
 
 

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



Posts: 110

Re:  shadow distance conditional on key docs
Reply #2 - Jan 28th, 2009, 6:02pm
 
thanks Mark.  I'm trying to achieve something slightly different - the container is not a keyref. its just holds notes, some of which are key refs, some arent.  Once any particular container holds, say, 5 notes which are keyrefs (i.e. the container might hold 8 notes in total, 5 keyrefs and 3 which arent marked keyref) I want the shadow to = 20.  

I hope that makes sense!

Thanks,

Ben
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re:  shadow distance conditional on key docs
Reply #3 - Jan 28th, 2009, 7:47pm
 
Give the container a rule to count the number of children that are key references.  

Then, you can set the shadow of the container  based on the KeyReferenceCount.
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re:  shadow distance conditional on key docs
Reply #4 - Jan 29th, 2009, 6:49am
 
[Note in this post red code doesn't actually work, blue does!]

@Ben. Although you're interesteted in notes where 'keyref' is true, you're also only interested if there are more than 4 (i.e. if 5 or more are true). Thus you only need our agent to test containers that have more than 4 children (see also Note 1):
AgentQuery: $ChildCount > 4

Now as per Mark B's suggestion we then test containers for the number of notes where the keyref attribute is true (ticked). In the following I've included some code that doesn't work as they were the intuitive but incorrect guesses one might make. So, this calls for a conditional count using the sum_if() action code operator:

AgentAction:
if((sum_if(child,$keyref=true,1))>4) {ShadowDistance=20} else {ShadowDistance=5}

...but this fails to work, most likely because sum_if isn't evaulated within the if condition. So we can try eval() for evaluating things, enclosing the sun_if() in an eval() call:

AgentAction:
if(eval(sum_if(child,$keyref=true,1))>4) {ShadowDistance=20} else {ShadowDistance=5}

...this too fails. As the manual doesn't clarify what degree of expression resolution is allowed in a conditional statement but we must assume that eval() is not supported in this context. The way around this is to create an extra attribute to hold the sum of true keyrefs and then use the attribute value in the if conditional statement. This does work:

AgentAction:
$MyNum=sum_if(child,$keyref=true,1); if($MyNum>4) {ShadowDistance=20} else {ShadowDistance=5}

For those new to more complex actions, it is often initially counter-intuitive to use additional attributes to 'park' evaluated intermediate values for use in the latter part of a complex action. Almost invariably the need for this approach is due to the scope/complexity evaluations, which aren't often apparent to the user. Initiatives are in hand to try help clarify what is/isn't evaluated and what needs a 'parking' like above but there is a lot of retrospective documentation to do.

Other notes:

1. If your containers and keyrefs are in a single part of your TBX, e.g. a container "Key Refs", then putting #inside("Key Refs")& on the front of your agent query will further constrain it's scope of action and increase efficiency by cutting the number of notes checked each agent cycle.

2. Whilst you may use any case you like for attributes general practice is to, like TB itself, give 'CamelCase' names to (user) attributes: ToDo, SKU, Garden. This isn't mere pedantry. As TB export/action codes don't use this case style it makes it much easier to review code as a CamelCase word is self-evidently an attribute, especially so if $ prefixes aren't used.

3. In the context of the agent's action neither count($keyref(child)) or sum($keyref,child) work - lest you be tempted to try them. For count to work, the $attribute(note) syntax would need to accept a group placeholder rather than an item, i.e. we're assuming a nested sub-count. For sum to work, we're assuming that for a Boolean data type both than only 'true' values are counted and these are coerced to a numerical value of 1.
Back to top
 
« Last Edit: Jan 29th, 2009, 6:54am 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:  shadow distance conditional on key docs
Reply #5 - Jan 29th, 2009, 11:28am
 
(Note explaining the some of the weirdness in the previous note: wonkish!)

In an agent action, we're examining properties of the note we're about to add to the agent.  So:

      if(sum_if(child, condition,1)) {....}

examines the children of the note -- not the children of the agent.  

Similarly,

    if($ChildCount>4)....

is true for notes that have 5 or more children.  You might test

    if($ChildCount(agent)>4)....

but this is evaluated when the note is added, and so depends on what notes have already been added.

The two-step approach avoids all these complications.
Back to top
 
 
WWW   IP Logged
Pages: 1
Send Topic Print