In LiveCode, an object by default does not contain any custom properties. But you can add, change or delete any number of custom properties of an object by using the property inspector. You can also add or delete any number of custom property by using script code. For example, a custom property can be given a value using the set command:
set the mycustprop of me to "Hello world"
If the above custom property already exists, then it will get a new value of "Hello world". if it does not exist, then it will be created and given the value "Hello world".
You can make changes to the value in a custom property by using the property inspector. You cannot make changes to the values in a custom property by using script code. However if you need to make changes, then put the value of a custom property into a variable. And make the change to the value of the variable. Then set the value of the custom property to that new value. You can also use Setprop and Getprop to do some additional processing.
In the following example - pCounter = 14 and the code is in the current card of this stack.
on Mymessage1 -- start of handler put the pCounter of this stack into temp -- temp = 14 add 1 to temp -- temp = 15 set the pCounter of this stack to temp -- pCounter = 15 end Mymessage1 -- end handler
Custom properties can be used in place of global variables. You can put data into a custom property by using one handler and withdraw that data by using another handler. For example, the following code is in a button on the current card of this stack:
On MouseUp -- start of handler put the pCounter of this stack into zemp -- zemp = 15 answer ("Counter is " & zemp) -- answer = Counter is 15 end MouseUp -- end handler
Custom properties are always placed on the default customPropertySet unless you specifically change it. Any custom property placed on default customPropertySet is Public, meaning that it can be accessed by any handler in the program. The example above shows this.
If you want to place a custom property on another customPropertySet you have to set it first, then access the custom property. To set it back to the default customPropertySet, set the customPropertySet to empty. The custom properties on one customPropertySet are totally different from any other custom property even if they have the same names. To place a custom property called Bob onto the customPropertySet called Fred, do the following:
on HiFive -- start message handler set the Bob of me to 22 -- Create Bob & set to 22 set the customPropertySet of me to "Fred" -- Create Fred & switch to it set the Bob of me to 55 -- Create Bob and set to 55 put the Bob of me into George -- Create George & set to 55 set the customPropertySet of me to empty -- switch back to default put the Bob of me into George -- Create George & set to 22 return George -- return George = 22 end HiFive -- end handler
The custom property called Bob on the default customPropertySet is a different custom property from the one by the same name on the customPropertySet called Fred. The custom property called Bob on the customPropertySet called Fred is protected somewhat from access. The only time this Bob can be accessed is when the customPropertySet is set to Fred. If HiFive is the only handler to set the customPropertySet to Fred, then only HiFive will be able access this Bob.You can see and edit custom properties visually with the property inspector: as well: