Scott Rossi wrote:

Recently, Garrett Hylltun wrote:

Is it better to use "send" or just use the name of the handler?

Short answer : Just use the name of the handler.
Long answer : see below.

on subCheckNow
  -- do stuff here
  send "subCheckNow" to me
end subCheckNow

Or this?

on subCheckNow
  -- do stuff here
  subCheckNow
end subCheckNow


Is the second even allowed? And, if it is allowed, is their any ill
effects from doing this?

I thought you might end up with recursion in the second option, but
apparently the script compiler doesn't like option 2.  So the answer to your
question seems to be: stick with option 1.

My script compiler doesn't object to it at all (Rev 2.6.1., WinXP). Did you maybe have both options in the script at the same time (in which case the script compiler would complain because there were two handlers with same name) ?

The second option calls the handler directly - i.e. in the same execution context, so as written it is indeed infinite recursion. Of course in a real script, the "do something here" would contain the possibility of an early exit from the handler. Similarly,the first option will continue to send messages to itself indefinitely unless there is some code that can exit earlier in the handler.

The docs say

Note: Using the send command is slower than directly executing the commands using the normal message path. For best efficiency, use the send command only when you want to delay the message or when the handler you want to execute is not in the message path.

Since you were sending to the same handler, it is in the message path, and also you had no delay specified - so it would seem you should never do option 1 in preference to option 2.



NOTE that a ""delayed send" (such as "send xxx to me in N ticks") is commonly used, because it queues the message, and therefore affects the order of execution. As the docs say,

Important! Specifying a time can affect the order in which statements are executed. If you don't specify a time, the message is sent immediately, and any handler it triggers is completed before the rest of the current handler is executed. If you use the send in time form of the send command--even if you specify a time of zero seconds--the current handler finishes executing before the message is sent.

but there seems to be no reason to use the "immediate" send to the same handler.



--
Alex Tweedly       http://www.tweedly.net

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.9.9/382 - Release Date: 04/07/2006
_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to