"Global" variables are placed at the top of your source code and define that the variable can be accessed absolutely anywhere:
Global g_Temp as integer
g_Temp = 5
MyTest()
Print g_Temp
wait key
end
Function MyTest()
g_Temp = g_Temp+5
EndFunction
Here, a global variable is used and altered within a function, so basically "global" lets you access a variable from anywhere in your proigram, and can be a great way of sharing data between several functions. Arrays are defined as global by default, by the way.
Now lets look at what happens if you just remove the word "global" from the above snippet:
g_Temp as integer
g_Temp = 5
MyTest()
Print g_Temp
wait key
end
Function MyTest()
g_Temp = g_Temp+5
EndFunction
The code runs, and prints 5 - but why? The function also uses a g_Temp variable, but it is not the same g_temp declared at the top. Within a function, all variables are "local" by default, or unique to within the function. The function will use local variables by default, if a global or a local variable with the same name exists.
So, you can declare variables within a function as "local" just to make sure that you don't alter a "global" variable by mistake.
Hope this helps!
We spend our lives chasing dreams. Dark Basic lets us catch some of them.