Command to execute some code
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Command to execute some code
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
Is so, what is it?
Thanks,
Larry
Re: Command to execute some code
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
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
Re: Command to execute some code
Hi.
What Klaus suggested is:
Field "yourField" has to have valid, clean LC statements.
Craig Newman
What Klaus suggested is:
Code: Select all
on yourRoutine
dostuff
do field "yourField"
end yourRoutine
Craig Newman
Re: Command to execute some code
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
'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
Re: Command to execute some code
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
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
Re: Command to execute some code
Thanks for the good advice Craig.
Larry
Larry
Re: Command to execute some code
Thganks, 'Do' was exactly what I needed. Here is a snippit of the code:
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'
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
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'
Re: Command to execute some code
Aha!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'
