Strange list thing

set valseltype to (valwintypearray's selectedObjects()) as record
log valseltype
log valdeftypes
log item -1 of valdeftypes
log valseltype is item -1 of valdeftypes --returns 1
log valdeftypes contains {valseltype} --returns 1
log valdeftypes contains valseltype --returns 0

here’s the full log:

I don’t understand why it needs the extra brackets! :cry:

Hi,

.because actually you are looking for the reference to a list (or record) element not for the contents

Consider that you have to define a list like

set myLIst to {1} & {2} & {3}

The first braces are obligatory, you could omit the other ones, AppleScript will coerce the integer values implicitly to a list item.
The syntax item x of aList dereferences the list item

You run into the same problem when you try to check for a boolean equation using the repeat with anItem in aList form. In this example the script will never say “yeah, two”

set myList to {1, 2, 3}
repeat with anItem in myList
	if anItem is 2 then say "yeah, 2"
end repeat

To get the expected result you have to dereference the list item by adding contents


set myList to {1, 2, 3}
repeat with anItem in myList
	if contents of anItem is 2 then say "yeah, 2"
end repeat

Thanks :slight_smile: