Comment about "do" (was clickLine/clickcharchunk)
Richard Gaskin
ambassador at fourthworld.com
Wed May 8 11:01:18 EDT 2013
dunbarx wrote:
> You can:
> put foo into the clickLine --and insert foo into a line in a field
>
> You cannot:
>
> get the clickLine
> put whatever into it -- and expect that foo will be inserted into
> a line in a field
>
> The foo will go into the variable it, not into the evaluated contents
> of it, which is a string containing a "valid" clickLine reference.
Maddening, but understandable.
Remember, we're talking about a machine too stupid to count past 1, so
we need to be very explicit about our intentions, sensitive to its
delicate nature. :)
In the first case, here's what the machine does:
1. determine the clickLine
2. put the value into that text position in the object
In the second case, it's doing something very different:
1. determine the clickLine
2. store that in the local variable "it"
3. put a different value into the local variable "it"
> So you have to use a "do" construction.
...in HyperTalk. With LiveCode's property-driven syntax options, this
works well:
get the clickLine
set the text of it to "whatever"
Here, the engine is doing:
1. determine the clickline
2. store that in the local variable "it"
3. "set" only works on object elements, so:
3a. determine if "it" is actually a valid element reference
3b. if so, set the specified property of that element
3c. if not, complain by throwing an error
At the heart of this is the ambiguity introduced with "put":
Sometimes "put" means setting the text of a container object, but
sometimes it means setting the value of a variable.
When you use it directly with a function call, no variable is involved
so it can figure out what you mean. But once a variable is introduced
it gets confused, since the "put" command is also used for variable
assignments.
In contrast, "set" can only be used to assign property values to object
elements, so the engine has no difficulty figuring out your intentions.
--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
Follow me on Twitter: http://twitter.com/FourthWorldSys
More information about the use-livecode
mailing list