FANDOM


In LiveCode when an object is created, by default it does not contain any custom properties. But you can add any number of custom properties by using script code or the Property Inspector.

For example, a custom property can be given a value using the set command:

set the mycustprop of button "Zook" to "Hello world"

If the above custom property already exists, then it will be given a new value of "Hello world". if it does not exist, then it will be created and given the value of "Hello world".

You can change the value of a custom property by coding or using the property inspector. But you cannot make partial changes to the values of a custom property by using script code. For example, you cannot add a second item to make the value into a list. The work-around is to put the value of a custom property into a variable. Then make the change to the value of the variable. Finally, set the value of the custom property to that new value.

For example: Suppose that pCounter = 14 and the following code is in the current card of this stack.

on Mymessage1                                       -- start of handler
  put the pCounter of this card into temp           -- temp = 14
  put comma & 11 & comma & 22 after temp            -- temp = 14, 11, 22
  set the pCounter of this card to temp             -- pCounter = 14, 11, 22
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 card into zemp          -- zemp = 14, 11, 22
   answer "Counter is " && zemp                     -- answer = Counter is 14, 11, 22
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 code above is an example of this.

The programmer can create a new customPropertySet, any number can be created. Each customPropertySet can contain any number of custom properties. A custom property in one customPropertySet is totally different than the custom property in another customPropertySet, even with the same name.

For Example:

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                   -- put 22 into George
  return George                                   -- return George = 22
end HiFive                                        -- end handler

The above handler creates the custom property "Bob" in the default customPropertySet and sets it to 22. Then it creates another custom property called "Bob" in the customPropertySet called "Fred" and sets it to 55. The custom property "Bob" in the default customPropertySet has a totally different value from the custom property "Bob" in the customPropertySet "Fred". It is even possible to delete one of them without affecting the other.

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 becomes Fred. If HiFive is the only handler to set the customPropertySet to Fred, then only HiFive will be able access this Bob.

If you want to place a custom property in another customPropertySet you may have to change to that customPropertySet first, then access the custom property. You can put it back to the default customPropertySet by setting the customPropertySet to empty.

You can also use Setprop and Getprop to do some additional processing.

You can add, change or delete any number of custom properties of an object by using the Property Inspector.

CustomProperties

Custom property editor, in the custom property page

CustomProperty2

New custom property window, form version 8

Community content is available under CC-BY-SA unless otherwise noted.