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.

 

This topic was last updated on August 19, 2021, at 03:30:51 PM.

Eggplant icon Eggplantsoftware.com | Documentation Home | User Forums | Support | Copyright © 2022 Eggplant