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
Getting $Name to be colored under certain conditio (Read 3788 times)
Ralph Alvy
Full Member
*
Offline



Posts: 85
Santa Monica
Getting $Name to be colored under certain conditio
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.
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Getting $Name to be colored under certain conditio
Reply #1 - 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.)
Back to top
 
 
WWW   IP Logged
Ralph Alvy
Full Member
*
Offline



Posts: 85
Santa Monica
Re: Getting $Name to be colored under certain conditio
Reply #2 - 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"}; 



Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Getting $Name to be colored under certain conditio
Reply #3 - 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).
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Getting $Name to be colored under certain conditio
Reply #4 - 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]
Back to top
 
« Last Edit: Jan 21st, 2015, 3:13pm by Mark Anderson »  

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



Posts: 85
Santa Monica
Re: Getting $Name to be colored under certain conditio
Reply #5 - 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.
Back to top
 
 
  IP Logged
Ralph Alvy
Full Member
*
Offline



Posts: 85
Santa Monica
Re: Getting $Name to be colored under certain conditio
Reply #6 - 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.
Back to top
 
 
  IP Logged
Ralph Alvy
Full Member
*
Offline



Posts: 85
Santa Monica
Re: Getting $Name to be colored under certain conditio
Reply #7 - Jan 21st, 2015, 3:40pm
 
Ah, wait. It looks like icontains() the case-insenstive version of contains(). Correct?
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Getting $Name to be colored under certain conditio
Reply #8 - 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.
Back to top
 
 

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



Posts: 85
Santa Monica
Re: Getting $Name to be colored under certain conditio
Reply #9 - Jan 21st, 2015, 7:27pm
 
Yes. Very helpful, as usual.
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print