What's wrong with Globals?

Devin Asay devin_asay at byu.edu
Mon Apr 2 18:49:44 EDT 2007


On Apr 2, 2007, at 4:27 PM, Joe Lewis Wilkins wrote:

> Graham and everyone else who is interested or should be,
>
> Since I started this thread with what I thought was a fairly naive  
> question with a pretty obvious conclusion, perhaps I should  
> summarize the input - if that is possible, what with some of the  
> quite lengthy monologues.
>
> I believe that Richard and Jim have made the most poignant  
> arguments both for and against the use of globals; and I was  
> leaning very sharply in the CP direction until Graham made a very  
> good point: CPs do tend to involve writing a lot more code, and I  
> have to learn something that I've not used before; hence probably  
> subject to some errors in usage on my part - typos and otherwise.

No one has mentioned what may be the most compelling reason to use  
custom properties in certain cases--the setProp structure. I used  
this for the first time about a year ago (I just had never noticed it  
before) and it opened up a whole new world for me. In a nutshell, one  
can use a setProp structure, whenever a custom property's value is  
set, to do whatever one wants. For instance, I was recently writing  
an app in which certain visual and behavioral things needed to change  
when a sound file was playing versus stopped. So I created a custom  
property isPlaying for the card and did something like this:

setProp isPlaying
   if isPlaying then
     set the icon of btn "play" to <pause icon>
     disable field "dialog"
   else
     set the icon of btn "play" to <back to the play icon>
     enable field "dialog"
   end if
   pass isPlaying
end isPlaying


Every time I start playing the sound file I also set the isPlaying of  
the card to true, then set it to false again when it stops. I've  
simplified the example here quite a bit, but this structure makes it  
much easier than trying to remember in which handlers you need to  
enable/disable things, change icons, etc.

You can also use setProp structures to validate data, to make sure  
it's in the property format or type or whatever.

Cheers.

Devin

Devin Asay
Humanities Technology and Research Support Center
Brigham Young University




More information about the use-livecode mailing list