If you declare a global variable in a stack script, do you have to declare it again in say a card script or button script that is going to use the variable?
i.e.
global myVar
is in the stack script
Do I have to repeat
global myVar
if I am going to use myVar in a button or card script?
Linda
Global variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Global variables
Hi Linda,
yes, a global vairable needs to be declared in every SCRIPT, like in these examples:
1. Stack or Card script, does not make much sense, but should show you how it works
Global is declared a the top of the script and thus available to all handlers in the script
2. Button or any other object script, only one handler, so this can be done INSIDE of the handler:
Hope this helps!
Best
Klaus
yes, a global vairable needs to be declared in every SCRIPT, like in these examples:
1. Stack or Card script, does not make much sense, but should show you how it works

Global is declared a the top of the script and thus available to all handlers in the script
Code: Select all
global gYourVar
on opencard # openstack
put 10 into gYourVar
end opencard
command my_handler
add 20 to gYourVar
answer gYourVar
end my_handler
Code: Select all
on mouseup
global gYourVar
put gYourVar into fld "display my global"
end mouseup
Best
Klaus
Re: Global variables
What Klaus said.
It may not be pertinent in your situation, especially if the value you want to access across scripts is small, but do consider using custom properties. These are just as ubiquitous, can be of far greater richness in terms of what you are actually storing, and survive sessions. They are like a "super global".
Craig Newman
It may not be pertinent in your situation, especially if the value you want to access across scripts is small, but do consider using custom properties. These are just as ubiquitous, can be of far greater richness in terms of what you are actually storing, and survive sessions. They are like a "super global".
Craig Newman