Best Practices

Jim Ault JimAultWins at yahoo.com
Sun Nov 6 13:41:34 EST 2005


Good questions, Erin.
On 11/6/05 9:59 AM, "Erin D. Smale" <esmale at welshpiper.com> wrote:
> Still plugging away at the tutorials,
> 
> * Functions: From what I read, a function can be called by any other
> handler in a given script. Is it therefore best to define functions at
> the beginning of a script, before any event handlers?
The function can be located anywhere in the same object or further up the
message hierarchy.  Think about a back script as the last location and could
theoretically contain all of your function handlers for all of your stacks.
The practical location for most functions would be somewhere in the stack
script if they only are used by the current stack.
---- from the Rev docs -----
To create a code library, place the handlers you want to re-use in any
object that's available in your stack, then use the insert script command to
add that object to the message path (use INSERT SCRIPT on openStack)
Handlers (eg. functions) in that object's script are now accessible to any
other handler in Revolution. ... It receives messages after any other
object, and just before the engine receives the message. The BACKSCRIPT
object remains in the message path until the end of the session (or until
you remove it with the remove script command.)
--- from the Rev docs -----
The START USING command inserts the stack at the END of the message path,
after the object's stack and main stack, but BEFORE objects that have been
inserted into the BACK with insert script.
---

>If I want to open 
> a function up to the whole application, should I define it in its own stack?
[me again]  This means that placement of the script container is the key to
building a library of handlers (functions & procedures). Placing an entire
stack puts its stack script at the end of the message path, and also that of
the current card in that stack.  Inserting the script container of an object
(button, card, stack) will put that container at the end of the path AFTER
any 'stacksinuse'.

> * Variables: I understand that vars are defined when they're initialised
> (except globals, which need to be declared). This upsets my sense of
> order somewhat, but I can see the advantages. That said, is it best to
> declare variables anyway? Is there any performance impact if I do or
> don't? Is it best practise to use the explicitVariables property?
> 
> * Variable type: The variable types are easy enough to distinguish, but
> I'm still getting used to Transcript, so I want to make sure I'm using
> them properly. Can someone check my work here:
> 
> (1) Local variable - accessible only within the handler that contains it
> (declare within a handler).
>      on someHandler
>          local intValue = 5
>      end someHandler
> 
> (2) Script local variable - accessible to all handlers within the script
> that contains it (declare within a script, outside any handler).
>      local intValue
> 
>      on someHandler
>          intValue = 5
>      end someHandler
> 
>      on someOtherHandler
>          intValue = intValue * 5
>      end someOtherHandler
>    
> (3) Global variable - accessible to all handlers in the application
> (declare in or out of a handler).
>      global intValue
> 
>     -- Various handlers in various scripts that manipulate intValue
>
Correct.  One extra note on Rev development environment.  Globals are owned
by Rev.  Simply closing a main stack and its sub stacks will leave them in
memory, and the globals they created will still be in Rev.  Closing and
removing from memory will purge all of the objects and scripts, but NOT the
globals.  The globals will persist until you quit Rev.  Sometimes I put
empty into large size globals to ease memory requirements for Rev.


Jim Ault
Las Vegas





More information about the use-livecode mailing list