Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Getting $Name to be colored under certain conditio
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1421866112

Message started by Ralph Alvy on Jan 21st, 2015, 1:48pm

Title: Getting $Name to be colored under certain conditio
Post by Ralph Alvy on Jan 21st, 2015, 1:48pm

I'm trying to get an outline title to turn red under certain conditions and find this fails to do anything at all:


Code:
If (condition){$NameColor = "bright red"};


Probably something obvious.

Title: Re: Getting $Name to be colored under certain conditio
Post by Mark Bernstein on Jan 21st, 2015, 2:03pm

The color of a note in outline view is $Color, not $NameColor.

(Note that document settings can request that outlines use darker colors, or black, in place of $Color.)

Title: Re: Getting $Name to be colored under certain conditio
Post by Ralph Alvy on Jan 21st, 2015, 2:17pm

Ah, okay. And, though I find


Code:
$Color="bright red"


turns the outline note title to red when I use that as a rule, the following test to see if I understand how to construct a conditional does not:


Code:
If(1=1){$Color="bright red"};



Title: Re: Getting $Name to be colored under certain conditio
Post by Mark Bernstein on Jan 21st, 2015, 2:27pm

"if" must be lowercase in Tinderbox actions (and in almost every language I've seen since good old FORTRAN, when we didn't have lowercase letters).

Title: Re: Getting $Name to be colored under certain conditio
Post by Mark Anderson on Jan 21st, 2015, 2:32pm

Check out $Color, $Color2 and $NameColor. $Color is the main color of a map icon and used for the colour of the note title in all other views**. $NameColor is used for the colour of the title on map icons.

** In Outline & chart views, there are settings in Document settings/Outline that set note titles to use a darker tint of $Color or use a pure black for all titles.

For conditionals, use if(){}. Note that the 'if' is lowercase & case-sensitive. The initial condition must resolve to a true/false result:

if(true/false test){true code}
or
if(true/false test){true code}else{false code}

So:

if($Name.contains("red")){$Color="bright red"}else{$Color=;}

Any note called red or whose title contains the sub-string 'red' will be coloured red. All other notes will have $Color reset to use the default $Color value.

Semicolon terminators. Both inside the {} and after the final } a semi-colon is only required if there is another discrete expression within the overall code:

if($Name.contains("red")){$Color="bright red";$NameStrike=true}

if($Name.contains("red")){$Color="bright red"};$Pattern="diagonal"

[edit: fixed error in code example]

Title: Re: Getting $Name to be colored under certain conditio
Post by Ralph Alvy on Jan 21st, 2015, 2:54pm

Yep. That's the problem. I'm used to scripting with Filemaker where this is not the case. And I had though I read somewhere TB coding was all case-insensitive. Probably it was just quoted strings.

Title: Re: Getting $Name to be colored under certain conditio
Post by Ralph Alvy on Jan 21st, 2015, 3:02pm

I posted my reply above without seeing your lengthy reply that preceded it. That long reply is very very useful to me. Thanks.

Also, in the online tutorial I noticed use of $Name.icontains() and I've been using that. I see you used Name.contains(). So apparently the dollar sign is no longer needed, and for some reason there was an 'i' in there that is no longer needed.

Title: Re: Getting $Name to be colored under certain conditio
Post by Ralph Alvy on Jan 21st, 2015, 3:40pm

Ah, wait. It looks like icontains() the case-insenstive version of contains(). Correct?

Title: Re: Getting $Name to be colored under certain conditio
Post by Mark Anderson on Jan 21st, 2015, 3:41pm

Oops single typos and 2 resulting copy/paste errors now fixed. OK, for clarity, Name.contains() or similar will likely work, but for legacy support reasons. Put another way, it's best no to start out learning syntax that may stop being supported - and I apologising for inadvertently contributing to the confusion.

Early in TB's existence, action code was much, much smaller in the scope of what it could do. You could write code like:

Color = bright red

TB would guess you meant the attribute Color should be set to the string value   'bright red', by cutting up the expression, checking the bit left of the operator matches a currently defined attribute, etc. Easy for the user to just write what they mean except with more complexity the method doesn't scale well. So now, we'd write:

$Color = "bright red"

Now TB immediately knows we're setting the value of an attribute to a string value - it doesn't have to work out if the value is "red", "bright" or "bright red", it uses the provided quotes. However, there are plenty of users out there with old docs that don't want to update (nor know how to) so the old code is supported. That's why I list it as 'deprecated' in aTbRef. It may work, but it's not best practice to do so.

Also, as action code gets more complex, 'rules' make learning easier - you quickly spotted my earlier typo of omitting a $, using 'Name' not '$Name'.

So it's complicated! But I hope that's helped give some background.

Meanwhile, with .contains() and .icontains() use the latter if you absolutely want a case-insensitive match and wend to override any lurking case-sensitivity switches.

Title: Re: Getting $Name to be colored under certain conditio
Post by Ralph Alvy on Jan 21st, 2015, 7:27pm

Yes. Very helpful, as usual.

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.