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.
How Global is global?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
You have to declare/initialize that variable the first time you use/fill it.
e.g.
And then you have to declare it everytime you use it like in a button:
Best
Klaus
e.g.
Code: Select all
on openstack
global gVar1
put 33 into gVar1
...
end openstack
Code: Select all
on mouseup
global gVar1
add 66 to gVar1
## or whatever...
answer gVar1
end mouseup
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
- Contact:
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
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode