>A side note--processing is faster if you do your if statement like this:
>
>if the mouseH < 475 then
>   if the mouseH > 385 then
>     if the mouseV < 393 then
>       if the mouseV > 370



I just did a test of the different techniques. Here's the movie script:

on mt0
end

on mt1
   if (the mouseH < 475 and the mouseH > 385 and  the mouseV < 393 and 
the mouseV > 370) then
     nothing
   end if
end

on mt2
   if the mouseH < 475 then
     if the mouseH > 385 then
       if the mouseV < 393 then
         if the mouseV > 370 then
           nothing
         end if
       end if
     end if
   end if
end

on mt3
   if inside(the mouseloc,rect(385,370,475,393)) then
     nothing
   end if
end


and here's the frame script:

on exitFrame
   times = []
   m = the milliseconds
   repeat with a = 1 to 1000
     mt0
   end repeat
   append times,the milliseconds - m
   m = the milliseconds
   repeat with a = 1 to 1000
     mt1
   end repeat
   append times,the milliseconds - m
   m = the milliseconds
   repeat with a = 1 to 1000
     mt2
   end repeat
   append times,the milliseconds - m
   m = the milliseconds
   repeat with a = 1 to 1000
     mt3
   end repeat
   append times,the milliseconds - m
   put times
   go the frame
end


The empty handler m0 is just to help time the 1000 repeat loop and 
handler calling. On my machine it came out as 8 milliseconds. The 
all-in-one-line-if technique took 56 milliseconds. Kerry's suggestion 
varied from 22 to 59 milliseconds, and my suggestion (which I'm now 
making) of using the Inside() function took 46 milliseconds.

Bearing in mind that this was a 1000 checks, we're not talking about 
much time difference per check. If you take away the 8 milliseconds 
overhead for calling the handler, that leaves it as 48, 14-51, and 38 
respectively. Which way to use may depend on the likelihood of the 
test being true, for example if the mouse is within that rectangle of 
the screen Kerry's routine would be somewhat slower than mine, and 
only marginally slower than the first method. If the mouse isn't to 
the right of the screen Kerry's routine would be quite a bit faster. 
On average his routine should come out a tiny bit faster than mine.

This is an easy case where checking coordinates isn't that demanding. 
Kerry's approach would be even more useful if the later tests were 
more demanding, for example:

if the mouseh > 600 and random(6) < calculatepi()

where calculatepi is a function that calculates pi to 10 decimal 
places, would be a very slow check every time. Testing the mouse > 
600 and only then calculating pi would be a lot quicker most of the 
time.


Meanwhile, back at reality, your situation isn't so demanding, and if 
you waste an extra 30 micro seconds it's not the end of the world.




[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to