Page 1 of 1

Accessing property values

Posted: Wed Mar 04, 2015 9:07 pm
by sefrojones
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

Re: Accessing property values

Posted: Wed Mar 04, 2015 10:31 pm
by dunbarx
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

Re: Accessing property values

Posted: Thu Mar 05, 2015 5:33 pm
by jacque
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