setProp and Lock messages

Richard Gaskin ambassador at fourthworld.com
Mon Dec 5 12:39:20 EST 2011


Pete wrote:

 > On Sun, Dec 4, 2011 at 12:10 PM, Richard Gaskin wrote:
 >>
 >> Here's what the docs say with regard to recursion for setProp:
 >>
 >>   Caution! If a setProp handler in one object's script sets the
 >>   custom property for a different object, and the first object
 >>   is in the second object's message path, a runaway recursion
 >>   will result. For example, if the following handler is in a
 >>   card script, and you set the "myCustomProperty" of a button
 >>   on the card, runaway recursion will result:
 >>
 >>    setProp myCustomProperty newValue
 >>      set the myCustomProperty of the target to newValue + 1
 >>      -- Because the target is the button, and this handler is in
 >>      -- the card, the above statement sends another setProp trigger
 >>      -- to the button.
 >>    end myCustomProperty
 >>
 >>   To avoid this problem, set the lockMessages property to true
 >>   before setting the custom property.
...
 >
 >
 > Hi Richard,
 > You're right the reference manual does say that.  And on the very next
 > page, it says:
 >
 > "If you use the set command within a setprop handler to set the custom
 > property for the current object, no setProp trigger is sent to the
 > target object. (This is to avoid runaway recursion, where the setprop
 > handler triggers itself)".
 >
 > Your example and mine appear to contradict each other so I guess
 > there must be two different circumstances described by these two
 > references.


In my pre-coffee state it seems we're looking at the same thing, with 
one small but important distinction:

Recursion will not occur if the setProp handler for a given property 
label sets the value of a property using that label, BUT if it calls any 
other handler which sets that property then recursion will occur.

Did I miss something?

--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  LiveCode Journal blog: http://LiveCodejournal.com/blog.irv





More information about the use-livecode mailing list