Trouble with Global Variable

 

I can't retrieved a Global Variable in an EA. First I am setting a Global Variable with a script. Then I am attempting to read the Global Variable in an EA. Here is the code and errors. What is wrong?

script...

int start()
{
   int testVar;
   GlobalVariableSet(testVar, 12345);     // set the global variable
   int xyz = GlobalVariableGet(testVar);  // get the global variable just as a test
   Print("Script: ",xyz);                 // prints: "Script: 12345"
   return;
}

EA...

      int abc = GlobalVariableGet(testVar);  // get variable
      Print("Error: ",GetLastError());       // prints, "Error: 4058". global variable not found
      Print("Result: ",abc);                 // prints, "Result: 0"
 
Do you have another expert running that deletes GVs?
 

Most probably is like that.


@ MisterDog

After setting up a Global Variable with a script, open GV inside terminal and see if the GV is set or not.

You track and do troubleshooting first.

 

This is the first time I've looked at a global variable in the terminal. I found it by pressing F3. Yes -- the value of "12345" is there.

And guess what I found out. The EA has to be loaded and running for this to work! Somewhere in the process the EA got unloaded. Thanks for the education everyone.

 
MisterDog:

This is the first time I've looked at a global variable in the terminal. I found it by pressing F3. Yes -- the value of "12345" is there.

And guess what I found out. The EA has to be loaded and running for this to work! Somewhere in the process the EA got unloaded. Thanks for the education everyone.

The first parameter if GlobalVariableSet/Get is a string, it's probably better to not use an int.
Reason: