Our final standard variable type is a Global variable. What makes these unique is that they can be accessed from anywhere within your application (as long as they are declared). The following is our repeat loop example edited for globals. This time we are using two buttons
Button 1
global gAdd
on mouseUp
repeat with x = 1 to 10
add 1 to gAdd
end repeat
put gAdd
end mouseUp
Button 2
global gAdd
on mouseUp
put "the value of gAdd is" && gAdd
end mouseUp
Like before, we have our repeat loop adding 1 to our variable 10 times. As our variable is now global, we have to declare it as such with the Global command.
You will have to declare this variable wherever you want to access it and this is what I have done in button 2. Now, I can set the variables value in 1 button and I can easily access this value in the 2nd button.
Although Global variables have their place, using them can lead to some headaches so using an alternative to these might be an option. The following LiveCode lesson explains these alternatives and how to use them-
http://lessons.runrev.com/m/4071/l/13158-what-are-the-alternatives-to-using-global-variables