Set the Behavior Not Working

Richard Gaskin ambassador at fourthworld.com
Mon Aug 31 19:37:13 EDT 2015


Roger Guay wrote:
 > I think I understand your point here, Richard, except the association
 > with your last sentence. I thought the long id would insure the use
 > of a behavior of buttons outside the host stack. Put here is the
 > thing:
 >
 > I successfully used this:
 >
 >   "set the behavior of last image to the long id of button
 >        “myCoolBehavior" of card  “Main””
 >
 > (card “main” is in myCoolSameStack stack)
 >
 > When I use the message box for the behavior of that image, I get:
 >
 >   "button id 1721 of stack “myCoolSameStack””
 >
 > why then can I not script:
 >
 >    “set the behavior of the image to button id 1721 of stack
 >        “myCoolSameStack"?

An object reference can be a string, or an expression that evaluates to 
a string.  For example these put the same string into the variable tVar:

   put the long id of btn id 1721 of stack "SomeStack" into tVar
   put "btn id 1721 of stack "&quote& "SomeStack" &quote into tVar

The difference between that second expression and the example you gave 
above that didn't work is that when using the "set" command the tokens 
following it will be evaluated.

When quoted, or prepended with "the long id of ", the result of that 
expression is a string, which is then used by the "set" command.

But without quotes the expression is evaluated, which results in "set" 
using the contents of the button.

This ambiguity in xTalk was handy in allowing us to do things like this:

   put fld 1 + fld 2 into fld 3

...but comes at a cost to ambiguity, since you're not the first person 
I've come across who expects an object reference to be treated as an 
object reference rather than as a series of tokens to be evaluated.

Lately I tend to prefer property-driven syntax for its clarity:

   set the text of fld 3 to the text of fld 1 + the text of fld 2

Much more cumbersome to write, but avoids the whole question of whether 
I'm referring to a property of the object or the object itself.

This "explanation" may only add to the confusion, but there's the rub: 
for all the seeming simplicity of xTalk, there are more than a few such 
ambiguities, which can make it harder to learn.  And I believe this one 
is among the ambiguities LiveCode Builder addresses.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list