Universal Variables

Hi,
I'm unable to access the universal variables that i have decalred in mhy scripts.

Scenario is:

In my Testsuite I have 3 scripts (script1, script2, script3). Script3 uses script1 and Script 2 (with help of Start Using ).

Script 2 has function setUniversalVariables where i set my universal variables(univar1,univar2) with initial values. and in the course of script 2 these values get modified.

Now, when I access these Universal variables for ex: TypeText UniVar1
instead of displaying values of UniVar1 it just displays text Univar1.

Please advise on how do I access the Universal variables declared.

Thx in advance.

-Veena

Comments

  • clisscliss Member
    My understanding is if you want to access these vars you need to declare them as globals in each script or function they will be used.

    ~Charles
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    That's right. To access either a global or universal variable, it must be declared as such. Otherwise that variable will be treated as a local variable.

    There are two different ways you can declare a variable as global. Either use the word "global" before the variable name everywhere you use it, like this:
    put 7 into global daysInWeek
    
    Or, declare it at the beginning of your script:
    global daysInWeek
    put 7 into daysInWeek -- sets the global variable
    
    If you declare the variable at the beginning, then every use of that variable name will refer to the global variable, but only within the script or handler where the declaration appears. To use it in another script or handler, you'll have to declare it again there.

    Keep in mind that SenseTalk offers both global and universal variables, which are distinct from each other. Universal variables are declared and used in exactly the same way as global variables. You can use either or both in your scripts. The difference between them in Eggplant is that universal variables retain their values between script runs (until you quit Egglant), while global variables are cleared at the end of every script run.
  • Hi,
    I'm unable to access the universal variables that i have decalred in mhy scripts.

    Scenario is:

    In my Testsuite I have 3 scripts (script1, script2, script3). Script3 uses script1 and Script 2 (with help of Start Using ).

    Script 2 has function setUniversalVariables where i set my universal variables(univar1,univar2) with initial values. and in the course of script 2 these values get modified.

    Now, when I access these Universal variables for ex: TypeText UniVar1
    instead of displaying values of UniVar1 it just displays text Univar1.

    Please advise on how do I access the Universal variables declared.

    Thx in advance.

    -Veena




    Hi Veena instead of "Typetext UniVar1" try "Typetext Universal UniVar1"
    this should work.
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    The important thing to remember is that each script is independent from other scripts, so global and universal variables must be declared in each script where they are used, either using a global or universal declaration statement or by including the word global or universal before each use of the variable name.
  • The important thing to remember is that each script is independent from other scripts, so global and universal variables must be declared in each script where they are used, either using a global or universal declaration statement or by including the word global or universal before each use of the variable name.

    and another thing (that burned me initially) is if you have a handler declared later in the script file, you need to declare your globals and universals inside them as well.
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Good point. Technically, I should have said "each handler" not "each script". If you don't have multiple handlers in a script then the only handler is the script itself. But if you have other handlers, then each one is independent and globals and universals will need to be declared in each handler.
  • Make sure the Universal Variable that you have declared has the Latest Value.
    Try something like this..

    Universal abc (**Declare the variable abc as Universal**)
    put "veena" into abc (**Putting a value into the Universal Variable abc**)
    now if you type
    put abc //this will type "abc".
    so if you type
    put universal abc //this will type "Veena"

    One more thing is that you need to run the Script where you have declared the Universal Variables the first time you start Eggplant else the Value will not be set.
    Hope this helps.. I may be wrong but this is how i am using the universal variables in my scripts.
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Yes, universal variables only persist during a session, so each time you launch Eggplant you'll need to assign values to any universal variables that your scripts rely on.

    Local and universal (and global) variables are distinct from each other, so if you don't explicitly declare variable 'abc' as global or universal you can actually have three different 'abc' variables in a handler: 'abc' (the local variable), 'global abc', and 'universal abc', each with their own values.
  • harshakm wrote:
    Make sure the Universal Variable that you have declared has the Latest Value.
    Try something like this..

    Universal abc (**Declare the variable abc as Universal**)
    put "veena" into abc (**Putting a value into the Universal Variable abc**)
    now if you type
    put abc //this will type "abc".
    so if you type
    put universal abc //this will type "Veena"

    One more thing is that you need to run the Script where you have declared the Universal Variables the first time you start Eggplant else the Value will not be set.
    Hope this helps.. I may be wrong but this is how i am using the universal variables in my scripts.

    As harshakm said,I access universal variables sucessfully.Just add a statement before I refer to the universal variables :
    run "universal_variables_script"
    "universal_variables_script" is the script in which I declared the variables.
Sign In or Register to comment.