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
Extra (unwanted) characters in DisplayExpression (Read 1004 times)
Marianne Høyen
Full Member
*
Offline



Posts: 6

Extra (unwanted) characters in DisplayExpression
Jun 30th, 2016, 1:12pm
 
I try to change a $DisplayExpression for the title of my notes.

As key attribute I have

Firstattribute  Cat
Secondattribute Dog

I want the result to be Cat: Dog

However, when I in the title pane of the text writes $Firstattribute+": "+$Secondattribute the result is

Cat;:;Dog

?

I have copy-pasted the information Cat and Dog from another system, and I suspect that doing this introduced some unwanted 'dirt'.

Do some of you have any suggestions about how to get rid of that?

BW

Marianne

Edited:
[admin edit - fixed unintended smiley in example problem output code. How? Tick the "Check this if you'll be adding code (or don't like smilies)." box at the bottom of the message editing page, i.e. under where you type your message]
Back to top
 
« Last Edit: Jun 30th, 2016, 2:35pm by Mark Anderson »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Extra (unwanted) characters in DisplayExpression
Reply #1 - Jun 30th, 2016, 2:34pm
 
Experimenting, it looks like your $Firstattribute (possibly both) are list attributes, i.e. a List or Set Type.

In the following my user attribute names show the data type used. I set $MyString1 to "Cat", $MyString2 to "Dog" and $MyList to "Cat". Now as you did I typed a display expression into the window on the Text Inspector. Typing in:

$MyString+": "+$MyString2

gives: Cat: Dog

$MyList+": "+$MyString2

gives: Cat;:;Dog

The latter is because Tinderbox thinks you're trying to add to a list. We can get around this (presuming the first attribute must be a list) thus:

eval($MyList)+": "+$MyString2

The eval() call evaluates the list value to a string so normal concatenation of strings (i.e. joining of texts) happens as expected.

~~~
LATER... Mark B, has since noted a better option for List/Set data in the above scenario. In stead of eval, use:

$MyListOrSet.format(", ")+": "+$MyString2

The format command takes the list and inserts the formatting sting - here a comma+space - between each list item.  If the list has only one item as here, you just get back the value!
Back to top
 
« Last Edit: Jun 30th, 2016, 4:00pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Marianne Høyen
Full Member
*
Offline



Posts: 6

Re: Extra (unwanted) characters in DisplayExpression
Reply #2 - Jun 30th, 2016, 2:49pm
 
You're right! The eval() worked fine.

I found that using other than pre-defined attributes doesn't cause the same problem....

BW
Marianne
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Extra (unwanted) characters in DisplayExpression
Reply #3 - Jun 30th, 2016, 3:49pm
 
Are you sure you want these to be list attributes?

- - -

I'm not wild about this use of eval.  A better way to coerce a list to a string is

  $MyList.format(",")
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Extra (unwanted) characters in DisplayExpression
Reply #4 - Jun 30th, 2016, 3:54pm
 
The underlying issue is the Data type of the attribute. The problem you originally described should only occur with List or Set types.

If you want to know the data type of an attribute, you can look at it in the Inspector. For system (built-in) attributes, you may find this list a quicker way to look things up.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Marianne Høyen
Full Member
*
Offline



Posts: 6

Re: Extra (unwanted) characters in DisplayExpression
Reply #5 - Jul 1st, 2016, 2:55am
 
OK - no, I don't want lists. It just happens.

I use Authors and Booktitle which both in the list, you refer to, are listed as set. Why do they act as lists, do you think? I alto use some user-defined attributes Then the problem does not appear.

A solution might be not to use reference attributes at all. TBX makes a wrong import (I have emailed to support about this problem, and they told me that the implementation of references were ad hoc and would be corrected in a future version of TBX (issue 1818)).
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Extra (unwanted) characters in DisplayExpression
Reply #6 - Jul 1st, 2016, 3:50am
 
When I spoke generically of a 'list' I was referring to all attribute that supports multiple values. Two of the attribute Data type in Tinderbox support multiple values: List or Set types. I commend following those links and reading the articles and exploring out from there in aTbRef. The main difference between Lists and Sets is sets do not support duplicate values.  If the 2 value of a List or Set were "Cat;Dog" (semi-colon is the value delimiter) then adding the value "Cat" would result in a List value of "Cat;Dog;Cat" but a Set would have the result "Cat;Dog" as the duplicate is ignored.

$Authors needs to be multi-value as a reference (book, paper, etc.) often has—outside fiction—more than one author. More specifically it is a Set-type attribute as duplicates in the attributes stored value(s) would be inappropriate.

So I don't see a mistake her.  If you look up what Set and List type do you'll see they are appropriate and that Set is a correct data type with $Authors.

The real issue here is that a single item list is still, under the hood, see a list consisting of one item. When using list attributes (i.e. List or Set data types) in action code you need to be aware that a reference to the attribute, e.g.$Authors, reference all values and you may need to use .format() to turn the value(s) into a string
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