Page 1 of 1
How Global is global?
Posted: Fri Feb 15, 2008 1:05 pm
by bjb007
Trying to set up a variable which will be available
to a number of button handlers but no matter where
I put "global theString" it isn't available when I want
it to be.
All suggestions considered.
Posted: Fri Feb 15, 2008 3:20 pm
by Klaus
You have to declare/initialize that variable the first time you use/fill it.
e.g.
Code: Select all
on openstack
global gVar1
put 33 into gVar1
...
end openstack
And then you have to declare it everytime you use it like in a button:
Code: Select all
on mouseup
global gVar1
add 66 to gVar1
## or whatever...
answer gVar1
end mouseup
Best
Klaus
Posted: Fri Feb 15, 2008 5:28 pm
by BvG
Globals are globals inasmuch as they
can be used in every part of a rev application. But to use them, you have to declare them in the respective context. If a variable is declared within a handler, like Klaus explained, it's only available as such in that specific handler. But you can also declare variables outside of handlers, making them available to every handler of the same object. So this would be a valid and working script:
Code: Select all
global someVarName
on mouseUp
put someVarName
end mouseUp
on mousedown
add one to someVarName
end mousedown