Global variables, Message Handlers, Functions

Rob Cozens rcozens at pon.net
Sun Aug 25 17:28:02 CDT 2002


Salut Benjamin!

>1.	Functions are used when we need to return something.
>	Otherwise custom handler are used for functions which would 
>return void like in C, say.

The MetaCard User Guide defines four types of handlers:

A. Message Handlers: "Message Handlers are statements beginning with 
the word on."
B. Function Handlers: "The difference between a function handler and 
a message handler is that a message handler is a statement..., 
whereas a function handler is called as part of an expression.
C. Setprop Handlers, and
D. Getprop Handlers which run when custom properties are set and 
called in an expression respectively.

Leaving aside the special issue of setprop/getprop, function handlers 
MUST return a value to be used when evaluating the expression 
containing the function call, and message handlers MAY optionally 
return a value. In the case of message handlers the value returned is 
obtained by checking the result function after the call. Eg:

	runMyMessageHandler arg1,arg2,arg3
	get the result

>2.	The keyword 'global' is the same as a global variable defined 
>in C but we hace to declare in all the handler, we use it.

Globals must be declared in all scripts that use them; but all 
handlers in a script can reference a global (or local, for that 
matter) variable declared outside of any individual handler.

>3.	Which card or stack handler should I use if I want to call a 
>custom handler, when the user close the current window, substack.
>	I tried closeStackRequest it launches my custom handler but 
>the stack does not close (?)

You must pass the closeStackRequest message OR include a statement 
such as "close this stack" in your custom handler.

Hope this helps.
-- 

Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.com/who.htm

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)



More information about the use-livecode mailing list