LC equivalent of the JS eval() function

Richard Gaskin ambassador at fourthworld.com
Sun Jul 24 12:25:51 EDT 2011


Slava Paperno wrote:

> I'm looking for the LC equivalent to the JavaScript eval() function. For
> example, if I have a variable called "tAddress" and I want an LC statement
> to assign a value to it, I'd like to say something like put "202 Main
> Street" into eval("tAddress").
>
> That may sound silly because if I, the programmer, know the name of the
> variable, I should say put "202 Main Street" into tAddress. But I don't know
> the name of the variable because it will be generated by a handler.

As Mark suggested, the "do" command or the "value" function will do what 
you need.

But this also seems a perfect fit for an array.

Arrays are a great solution when you don't know the number of elements 
you'll need to store, or will need to access them by names you can't 
know in advance, e.g.:

   put "202 Main Street" into tMyData[tAddress]
   put "Slava Paperno" into tMyData[tName]

--
  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