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
eval in Rules? (Read 4231 times)
Stefan Schwertheim
Full Member
*
Offline



Posts: 6

eval in Rules?
Dec 15th, 2009, 1:40am
 
Hello,

in a separat Note (Name TestXXX) I have the following statement:

if($SearchLiterature!=""){Badge="research"} else {Badge="none"};

In the Rule section of a different Note I use:

eval($Text(TestXX))

but nothing happens.

Can I use eval in Rules?

Stefan
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: eval in Rules?
Reply #1 - Dec 15th, 2009, 3:26am
 
Assuming reseferences to TextXX vs TextXXX are typos, it's worth noting that eval() needs a left-side argument and you don't provide one. As I understand eval(), it's purpose is for a differ problem to the one you're solving- it ensures that a given expressions is expanded (evaluated) before TB looks at the next expression, i.e. the code after the current expressions closing semi-colon. See the example in the aTbRef article I link to. From the eval() syntax, this ought to work - but doesn't:
  $Rule = eval("TextXX","$Text");

Note to worry, as actually we don't need eval here. This Rule works:
  $Rule = $Text(TextXX);
resulting in the note's Rule becoming:
  if($SearchLiterature!=""){Badge="research"} else {Badge="none"};

As you should only need to apply this action only once, this code is better as it only fires if the existing Rule is empty (which it isn't after one agent update cycle):
  $Rule |= $Text(TextXX);

Although the above works it may be you're trying to achieve more than a one-off attribution, e.g. by changing the code in TextXX and affecting lots of notes.  If so, try using prototypes instead of the above.
Back to top
 
« Last Edit: Dec 15th, 2009, 9:10am by Mark Anderson »  

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



Posts: 136
North Carolina
Re: eval in Rules?
Reply #2 - Dec 15th, 2009, 8:46am
 
Hi, MarkA:  This is very, very cool--just the sort of flexibility that I don't even think about asking from Tinderbox.

However, for those of us who are still learning:  Do you have an extra (  in there?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: eval in Rules?
Reply #3 - Dec 15th, 2009, 9:11am
 
Oops - yes I did. Well spotted. I've removed them now.  The extra '(' was the one just after the '=' (now gone!)
Back to top
 
 

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

User - not staff!

Posts: 5689
Southsea, UK
Re: eval in Rules?
Reply #4 - Dec 16th, 2009, 7:27am
 
My eval() page has been updated with a few more examples (via Mark B). Another example of eval is on the new page on exporting set-data lists.

It's worth re-examining why Stefan's original code failed. We asked TB to evaluate the $Text of note "TestXX":
  if($SearchLiterature!=""){Badge="research"} else {Badge="none"};
First, TB examines TestXX's $Text and the code there is evaluated. TestXX's $SearchLiterature attribute is examined a true or false Boolean is returned pointing TB to one of the two conditional outcome codes - the bits in {}.

If the first test was true, TB now tests TestXX's $Badge value. If it has a value of "research" a value of of true is returned as the rule. If the original test were false, and if the $Badge evaluates to "none" (or no string) again we get true back. Regardless of the outcome - true or false - we end up asking TB to write code like:
  $Rule = true
or
  $Rule = false
..which doesn't really work as a rule, thus no outcome.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print