On 7/10/11 9:29 AM, Slava Paperno wrote:
I'm curious about globals and the message box. I've been doing both
(omitting the global declaration and including it) and I haven't seen any
difference, but I've seen conflicting opinions in the posts here as well as
some forums. What's the skinny on this?

The message box has access to all globals for me, without any declarations. I don't use explicitVariables though; maybe that makes a difference.

It's also fine to put your global declarations inside each handler that needs to use it. It's become customary to put it at the top of the script but that isn't required.

In fact, to backtrack a bit, with explicitvariables set to false, it is actually possible to have both a global and a local variable with the same name in the same script as long as the global isn't declared at the top. I know we had a discussion about this before where I agreed it couldn't happen, but I've just tried it again and in fact you can, if you declare your global inside the handler:

on setup
  global testVar
  put 1 into testVar
  put testVar
end setup

on test
  put 2 into testVar
  put testVar
end test

Turn off explicitVariables and run "setup" first from the message box to make sure the global is initialized. After that you'll get different numbers depending which you call.

The failure I had when I tested before is that, like most people, I was declaring the global outside the handlers. I'd never recommend this kind of naming, of course.

--
Jacqueline Landman Gay         |     jac...@hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to