Accessing property values

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Accessing property values

Post by sefrojones » Wed Mar 04, 2015 9:07 pm

Hi all,

For as long as I've been using LiveCode, when checking a property of an object in an if statement, Checking the visibility of an image for example, I would do it something like this:

Code: Select all

If the visible of image "MyImage" is true then
dostuff
else
dootherstuff
end if
This is relatively easy to read any type, and I've never had a reason to look for another way. Today, I stumbled on the fact that I can use a property as a function (not sure if this is appropriate terminology).
It results in shorter, if slightly less readable code.

Code: Select all

if visible(img "MyImage") then
dostuff
else
dootherstuff
end if
A few quick experiments shows that this method of retrieving properties is not only available for booleans, but for others non-booleans as well.

Code: Select all

put height(this stack)


Has it always been this way? Is referring to the property as a function in this context correct? Or is this something else entirely? I see it's not mentioned in the LiveCode lesson on properties, or anywhere else that I've found...Can anybody shed some light on what is going on here on a deeper level?

--Sefro

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9785
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Accessing property values

Post by dunbarx » Wed Mar 04, 2015 10:31 pm

This has always been true. Goes back a long way. I do not see the duality documented in the dictionary for properties, however. HC did not permit this. You had to use the "the" form when dealing with properties.

As an aside, I have always had a hard time defining the difference between a function and a property. I know what they say, that functions return a value, and properties return a condition or a, er, a value. But one intrinsic to an object, as opposed to a value like "trunc"

So the "loc" is a property, but it returns a pretty distinct "value". The "foreColor" returns a color. That is an attribute. Oh well. Of course, you cannot set a function. It is therefore very important to know the difference.

Craig Newman

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7267
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Accessing property values

Post by jacque » Thu Mar 05, 2015 5:33 pm

An object's color is not a condition, it's another description of the object just as it's location is. Properties describe an object. Functions return a value, which can be one of those properties or anything else.

set the visible - - alter the object's description
get visible(object) - - return that description
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Talking LiveCode”