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
Need help with a rule (Read 5632 times)
Paul Walters
Ex Member




Need help with a rule
Mar 06th, 2009, 6:02pm
 
In 4.5.3 I had a document with a prototype that contained this rule

Code:
if(Critical) {$DueByPrint = "Critical"}; if(Important) {$DueByPrint = "Important"}; if(LongTerm) {$DueByPrint = "Longer Term"} 



Where Critical, Important, and LongTerm are all booleans, with default set to false.   DueByPrint is a string, default value is blank.

This rule does not work in 4.6.  In each note that uses the prototype with this rule, the value of DueByPrint is always "Longer Term", regardless of the state of Critical, Important or LongTerm.

What am I missing?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Need help with a rule
Reply #1 - Mar 6th, 2009, 6:46pm
 
Not tested, but I suggest you need to prefix the attribute names in the if conditions with a '$'. In the if(){} construct  -introduced in v3.0.0 - the simple boolean 'condition' used in the older ^if(condition)^ method became if(query){} where the query is an evaluated expression. If all that makes the barin a bit mushy (it does for me!), I think you should use:

if($Critical) {$DueByPrint = "Critical"}; if($Important) {$DueByPrint = "Important"}; if($LongTerm) {$DueByPrint = "Longer Term"}

But on testing (v.4.6) with only 'Critical' set to true I get the same results as you.  If I use an explicit syntax:

if($Critical=true) {$DueByPrint = "Critical"}; if($Important=true) {$DueByPrint = "Important"}; if($LongTerm=ture) {$DueByPrint = "Longer Term"}

I get DueByPrint equalling 'true'. Which is the same as I get if I test any one If condition on its own. Something odd happening here...
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Paul Walters
Ex Member




Re: Need help with a rule
Reply #2 - Mar 6th, 2009, 7:31pm
 
If...then...else tests are doing odd things

For example, if I reverse the test and use this rule:

$DueByTest |= "Critical"; if($DueByTest="Critical") {$Critical=true}   [or even {$Critical="true"}]

Critical does not get set to true

And for this rule:

if($Important) {Critical=true};

Critical is true even if Important is not (e.g. when a new note is created using the prototype with this rule.
Back to top
 
« Last Edit: Mar 6th, 2009, 7:43pm by Paul Walters »  
  IP Logged
Johnnie Wilcox - mistersquid
Full Member
*
Offline



Posts: 84
San Francisco, CA
Re: Need help with a rule
Reply #3 - Mar 6th, 2009, 7:50pm
 
It looks like there are collisions in the variable names and variable values. The following code works by giving $DueByPrint values distinct from the attribute variables that are being tested. Adjust to taste.

if($Critical=true) {$DueByPrint = "Is Critical"} else { if($Important=true) {$DueByPrint = "Is Important"} else { if($LongTerm=true) {$DueByPrint = "Longer Term"} else {$DueByPrint="" } } }

You'll notice that I've nested the logic so that if multiple items are true, only the first true item has an effect. This will prevent situations where Tinderbox keeps assigning new values to $DueByPrint. Given the names of your variables, it looks like the logic prioritizes the most important classification. Modify the testing order if this is not the case.

My own approach to avoid value-clobbering in cases like these is to use agents, expressing the logic with something like

if(LongTerm)&(!Critical)&(!Important) { do something here}

hth
Back to top
 
« Last Edit: Mar 6th, 2009, 7:56pm by Johnnie Wilcox - mistersquid »  
  IP Logged
Paul Walters
Ex Member




Re: Need help with a rule
Reply #4 - Mar 7th, 2009, 8:25am
 
That's the fix, alright!  Thank you Johnnie.

(If Eastgate did not intend that quoted strings would clash with attribute names ($Critical and "Critical"), then perhaps that's one for the bug list?)

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

User - not staff!

Posts: 5689
Southsea, UK
Re: Need help with a rule
Reply #5 - Mar 7th, 2009, 11:46am
 
I suspect it my be the law of unintended consequences. Eastgate have a difficult task here to update the workings of action code & syntax whilst not breaking all existing code.  If $Prefixes were mandatory, $Important = "Important"; or $Important = Important; can only be setting a string value. But as we still support Important = Important; there's scope for confusion.  Much of the change to quoting and $-prefixing is - I believe - to help avoid such head-scratchers for TB's parser.

FWIW, I tend to always use multi-word attribute names; $MyString, $StrTask, $IsDone, $BlnDone, $TaskDone. The camel case name helps me 'see' the attributes in the code (even without a $) and the secondary word can help indicate the data type - if there's scope for error, or simply forgetting over time.

My impulse is to create 'rules' syntax rules but actually the app is more forgiving than such rules might imply and making and Murphy's Law means that stating a notional rule is invariably a way of flushing the need for a (valid) syntax example that breaks it to do some less usual task!
Back to top
 
 

--
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: Need help with a rule
Reply #6 - Mar 7th, 2009, 4:16pm
 
It turns out that, in 4.6, evaluation of naked boolean predicates was wrong.  So
    if($Critical)  { ...
does not do the same thing as
    if($Critical=true) { ...

And, by bad luck, the test suite uses the second form.  This will be fixed in the next update.
Back to top
 
 
WWW   IP Logged
Pages: 1
Send Topic Print