Global variable

Hi,

I tried this but it's not working

SCRIPT1
global somevar

put "me" into somevar

SCRIPT2
put "somevar is" && global somevar

When I execute SCRIPT2 is displays this:
somevar is

Comments

  • EggplantMattEggplantMatt ForumAdmin admin
    How are you executing script2? If you're not calling script2 from script1, or calling them both from another script, then script2 is executing in its own context. Global variables only persist within a script run -- they don't persist between script runs or between the run of one script and then another. If you run this code, you should get the output you're expecting:
    global somevar
    put "me" into somevar
    script2 // this will execute script2 in the same context as script 1
    
    or given your existing scripts, putting this code in a third script would produce the same behavior/output:
    script1 // runs script 1, setting the global variable
    script2 // runs script2, accessing the global variable
    
  • All I want to do is call a global variable in my handler file that can be used by any script in the suite.
  • EggplantMattEggplantMatt ForumAdmin admin
    Global variables only exist/have values when they have been declared/set in the current script execution. If you just execute your script2 by itself, somevar will have no value because it has neither been declared nor set prior to your referring to it because script1 has not been run in that script execution.

    A universal variable will retain its value for as long as eggPlant is running, so that may be what you think you want, but this kind of variable usage is tricky to manage and dangerous as such things go.
Sign In or Register to comment.