Command to execute some code

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Command to execute some code

Post by lohill » Fri Dec 20, 2013 6:04 pm

Is there a LiveCode command that can be used in a routine to cause some other code contained in a field to execute as part of the original routine?
Is so, what is it?

Thanks,
Larry

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Command to execute some code

Post by Klaus » Fri Dec 20, 2013 6:07 pm

Hi Larry,

there is the "DO" command, maybe that is what you are looking for?
If not, maybe you can give a quick example (in pseudo-code)?


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Command to execute some code

Post by dunbarx » Fri Dec 20, 2013 6:15 pm

Hi.

What Klaus suggested is:

Code: Select all

on yourRoutine
  dostuff
  do field "yourField"
end yourRoutine
Field "yourField" has to have valid, clean LC statements.

Craig Newman

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Command to execute some code

Post by lohill » Fri Dec 20, 2013 6:34 pm

Thanks Craig and Klaus,

'Do' looks promising, I'll give it a try. Instead of do field "your field" could it also be "do tVariable' where tVariable contains the code?

I also se 'script' so it looks like I could set the script of some invisible button and then send "mouseUp" to it. In that case would it do the button script immediately before executing the rest of the calling routine?

Merry Christmas,

Larry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Command to execute some code

Post by dunbarx » Fri Dec 20, 2013 7:27 pm

Hi.

Yes, "do" can do the contents of any container, including variables: "do it"

But "do" is usually reserved for cases where an extra level of evaluation is required in order to make a line of code work properly. There are examples of this in the dictionary. There is also another, little documented set of circumstances where "do" is required in order for the LC parser to be able to make sense of what seems like valid code, but is not quite up to its standards. This is essentially performing another level of evaluation, which sets things right, and you will run across it one day.

In general, I like to keep my code in one place. If you need to send a message to an object somewhere, fine, but it is quite different to send, say, "mouseUp" to a button, which may be useful, than to do what you suggested, to keep a hidden button with code and use it as a library of some sort. This might work, but I would discourage it. Why break your handlers up if not really necessary? Better to use command or function calls, either elsewhere in the object script itself or perhaps higher in the natural hierarchy. I do not know your setup, but I bet you are complicating it.

Craig Newman

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Command to execute some code

Post by lohill » Fri Dec 20, 2013 11:30 pm

Thanks for the good advice Craig.

Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Command to execute some code

Post by lohill » Sat Dec 21, 2013 3:41 pm

Thganks, 'Do' was exactly what I needed. Here is a snippit of the code:

Code: Select all

            put the dgDataofIndex[tIndex] of group "DataGrid Rules" into tArray
            put tArray["Steps"] into tSteps
             put tArray["Notes"] into tNotes
            if tNotes is not empty then
               do tNotes
            end if
Before getting to do tNotes the values of the variables were:
tSteps: aprc>0
aprc>5
tNotes: if offset(tRelation,">=")>0 and tNum>0 then delete line 1 of tSteps

tRelation had a value of ">" and tNum was 5

tSteps after execution was just 'aprc>5'

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Command to execute some code

Post by Klaus » Sat Dec 21, 2013 4:41 pm

lohill wrote:,...Before getting to do tNotes the values of the variables were:
tSteps: aprc>0
aprc>5
tNotes: if offset(tRelation,">=")>0 and tNum>0 then delete line 1 of tSteps
tRelation had a value of ">" and tNum was 5
tSteps after execution was just 'aprc>5'
Aha! :D

Post Reply