メインコンテンツまでスキップ
バージョン:23.5

I created a global variable, but when I use it in another script, why is it empty?

Global variables have global scope, which means that their values can be accessed from any handler. However, declaring a variable as global in one place does not make every reference to a variable with the same name a reference to the global variable.

If you want to use a global variable in a different handler from the one in which it was declared, you need to either declare it as global in that handler as well or put the global keyword in front of the variable name.

To see examples of the two different ways to declare global variables (at the beginning of each handler, or in-line where necessary), see Global Variables: Example Scripts.

For more information about global variables as well as the other types of variables, see Variables.