Global Madness

Howard Bornstein howard.bornstein at gmail.com
Mon Mar 21 13:38:12 EST 2005


I must really be losing it. 

I've been working on an app in 2.5.1 and all was proceeding well. Then
I wrote a new handler and declared a couple of global variables.
Suddenly the globals weren't being seen as global. The handler worked,
but another handler that needed access to these values couldn't see
them (I know, I could use custom properties, but that isn't what this
email is about).

It didn't make any sense. So I grabbed a small portion of the code,
created a new stack, made a button and put the code in the button.
Here's the code:

on mouseUp
  
  global  gHeightScaler
  
  put the screenrect into sRect
  put item 4 of sRect into sHeight -- screen height
  put 102 into previewHeight -- fix the height to this value
  put previewHeight/sHeight into gHeightScaler
 
  put gHeightScaler
  
end mouseUp

When I run the script, it prints out gHeightScaler fine. But if I put
"put gHeightScaler" into the message box, it prints out
"gHeightScaler" instead of the value. If I look at the global tab of
the message box, gHeightScaler isn't listed.

What's really weird is that I modified the script in various ways,
including changing the name of the global variable. Sometimes, it
would get set as a global and other times not. I couldn't discern a
pattern regarding this. Once I was using the same global name
declaration and just messing with the value it contained. First it
wouldn't print the value from the message box, and then suddenly, it
just started working!

Here's the only thing I've been able to repeat:

If I put this line (this is arbitrary) "put 7.312 into gHeightScaler"
just before "put gHeightScaler" in the script, it prints out that
value and then the global works from the message box. If I then
comment out that line, the global continues to work from the message
box (with the correctly computed value). If I close the stack and
reopen it, the global continues to work (with that line commented
out). However, if I quit Rev and restart and then open the stack (with
the line commented out), the global doesn't work. If I uncomment the
line it works again following the entire process described in this
paragraph.

This is really driving me nuts. Have I missed something so completely
obvious that I need to burn my Rev unlock code?

Anyone seen anything like this WRT global variables? Any ideas? 
-- 
Regards,

Howard Bornstein
-----------------------
www.designeq.com


More information about the use-livecode mailing list