Do or don't do

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stecxjo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 11
Joined: Thu Sep 06, 2007 11:58 pm

Do or don't do

Post by stecxjo » Mon Mar 18, 2013 5:56 pm

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

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

Re: Do or don't do

Post by Klaus » Mon Mar 18, 2013 6:22 pm

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

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

Re: Do or don't do

Post by dunbarx » Mon Mar 18, 2013 7:08 pm

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

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

Re: Do or don't do

Post by Klaus » Mon Mar 18, 2013 9:09 pm

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

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Do or don't do

Post by sturgis » Mon Mar 18, 2013 9:48 pm

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

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

Re: Do or don't do

Post by dunbarx » Tue Mar 19, 2013 12:55 am

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

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Do or don't do

Post by sturgis » Tue Mar 19, 2013 1:02 am

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?

stecxjo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 11
Joined: Thu Sep 06, 2007 11:58 pm

Re: Do or don't do

Post by stecxjo » Tue Mar 19, 2013 5:56 am

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

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

Re: Do or don't do

Post by Klaus » Tue Mar 19, 2013 10:30 am

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

andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 184
Joined: Wed Apr 10, 2013 5:09 pm

Re: Do or don't do

Post by andrewferguson » Mon May 06, 2013 8:42 am

Hi,
The 10 line script limits will be removed from standalone applications built with the open source version of LiveCode.
Andrew

Post Reply