LC equivalent of the JS eval() function
dsc at swcp.com
Sun Jul 24 13:26:17 CDT 2011
People have already mentioned 'do', 'merge()' and using arrays.
I'll add these:
Set the script of an object.
Use a switch statement.
Set a chunk of the value of a variable, perhaps a global.
In limited situations, 'value()' might be useful.
Pass the variable to the function rather than its value using @.
Both 'do' and set scripts are limited to 10 lines in standalone applications. Perhaps 'do' is the most direct solution to what you want to do.
(I have found 'merge' to be powerful in some cases.)
I suspect what you want to do might be done well with a (perhaps global) variable containing an array. Like this:
put "202 Main Street" into stuff[ tAddress ]
However, maybe the @ fits into your scenario. Put an @ in front of a parameter in a hander (command or function) and when it is called with a variable the variable is passed not the value; use of the parameter is the same as the use of the original variable. This is much like pass-by-reference in Java. Like this:
on configureLocation @pAddress, @pCity, @pState, pLongitude, pLatitude
put "202 Main Street" into pAddress
(Having--tongue-in-cheek--thrown candy at speakers at a RunRev conference who promoted their "morals" in using variable prefixes, I have to say that the use of such prefixes above does not constitute a promotion of such use, but only exists as an aid in communicating the example.)
I wish you well in this.
More information about the use-livecode