Page 1 of 1

Do or don't do

Posted: Mon Mar 18, 2013 5:56 pm
by stecxjo
I seem to recall that at one time you could put a LiveCode script into a field's contents and then run that script with the "do" command:

on mouseUp
do fld 1
end mouseUp

It would be one way of showing a script in a field and then using a button to show what that script can do....

Or am I disremembering here?

--Steve

Re: Do or don't do

Posted: Mon Mar 18, 2013 6:22 pm
by Klaus
Hi Steve,

yes, you can still DO something like this!
A tiny test would have answered this question 8)

But there is a limit what you can DO, check "scriptlimits" in the dictionary!
And keep in mind that this might be up to 30 times slower than a "regular" script.


Best

Klaus

Re: Do or don't do

Posted: Mon Mar 18, 2013 7:08 pm
by dunbarx
Steve.

I read that the scriptLimits only applies to standalones. Just a comment. I could be wrong. But I wonder, why do you want to do it that way?

Klaus, about the speed thing? I tried this in a field:

Code: Select all

put the ticks into temp
put 0 into accum
repeat 1000000
add 1 to accum
end repeat
answer the ticks - temp
and then in a button:

Code: Select all

on mouseUp
   do fld 1

   --   get fld 1  --just a test, no difference
   --   do it
end mouseUp
No difference in time between all that "doing" and just putting the original script into a button.

Craig

Re: Do or don't do

Posted: Mon Mar 18, 2013 9:09 pm
by Klaus
Hi Craig,

oh yes, this only applies to standalones!

And execution speed surely depends on the complexity of the script.
Your repeat loop is not very complex per se 8)


Best

Klaus

Re: Do or don't do

Posted: Mon Mar 18, 2013 9:48 pm
by sturgis
And the repeat is in the do script so do is only called to compile 1 time. Should be very fast. If instead do was called 1000000 times I suspect the difference (in a standalone) would be quite noticeable. Doing a curiosity test right now, but think I should have done less loops! *twiddles thumbs*

EDIT: First test results back. Using do 51017 millisec. Non-do 1706

Still waiting on the other.

Code: Select all

on mouseUp
   put the milliseconds into tStart1
   repeat 10000000 times -- do method
      do field 1
   end repeat
   put the milliseconds into tEnd1

   put the milliseconds into tStart2
   repeat 10000000 times -- non-do method
      put random(100000) into tDummy2 -- same thing is in the field
   end repeat
   put the milliseconds into tEnd2
   
   answer merge("Do method: [[tend1 - tstart1]] non do method: [[tend2 - tstart2]]")
end mouseUp

Re: Do or don't do

Posted: Tue Mar 19, 2013 12:55 am
by dunbarx
And the repeat is in the do script so do is only called to compile 1 time. Should be very fast. If instead do was called 1000000 times
I certainly agree with that, but when would "do" be called more than once?

If even once?

Ah, but Steve is thinking about being able to see a script right in front of the user, and then invoking it, as opposed to having to open the editor and dig around.

I had asked why anyone would want to execute a script from a field, and think that this is a very reasonable, er, reason.

Craig

Re: Do or don't do

Posted: Tue Mar 19, 2013 1:02 am
by sturgis
Well true, and for that use its perfect.

I don't recall seeing this in the kickstart info but.. do you know if the scriptlimits will be removed in lcfree?

Re: Do or don't do

Posted: Tue Mar 19, 2013 5:56 am
by stecxjo
Thanks for the comments. I am using the field to show example code, for instance, how to use a variable within a repeat loop. It's really just for demo purposes. Of course, I can put the code also into a button to demonstrate, but I want my students to see the difference between doing something with ten lines of code vs just a few lines of code using repeat loops and variables.

I did try this out, Klaus, and what I found was that the DO didn't do what I thought the DO did. It didn't work. And this was not within a standalone, but in a stack that I'm currently putting together.

I discovered why it wasn't working, though. I had copied the mouseUp handler into the field as well and that just confused the hell out of the DO command.

I got DOO-DOO when it wouldn't do Do.

--Steve

Re: Do or don't do

Posted: Tue Mar 19, 2013 10:30 am
by Klaus
Hi Steve,

and don't forget that even the "Dodo" bird has died out along time ago:
http://en.wikipedia.org/wiki/Dodo 8)

:D


Best

Klaus

Re: Do or don't do

Posted: Mon May 06, 2013 8:42 am
by andrewferguson
Hi,
The 10 line script limits will be removed from standalone applications built with the open source version of LiveCode.
Andrew