Determine the scope of variables and attributes
Variables or attributes declared within an E-Prime 3.0 experiment are limited to the scope of the Procedure in which they are defined. Variables to be used only during a single trial may be declared and initialized at the trial level. For example, a variable used as a counter may be declared locally, as in the following example:
When InitializeArray is placed in the trial Procedure, both “i” and “arrValue” will be accessible during the trial. At the end of the trial Procedure, the “i” and “arrValue” variables will be discarded (e.g., the value of arrValue will not be accessible by an event at the block level).
If a variable is to be maintained or accessed across multiple executions of a Procedure (e.g., performance over a series of blocks), the variable must be declared globally in the User Script window. For example, a variable might be declared to keep track of the total number of trials. Use the View menu to display the User Script window in E-Studio and to declare a global variable.
Initialization of global variables cannot occur in the User Script window; instead, an InLine object would be used for this purpose. To initialize a global variable prior to its use (e.g., to initialize the number of trials to 0), use an InLine object placed appropriately. It is a good practice to initialize variInIables as the first event in the Procedure in which they will be used as part of the Procedure setup events. In this case, global variables exist throughout the scope of the experiment, so initialization should take place as the first event in the Session Procedure.
The global variable may then be updated during the trial level Procedure to maintain a count across multiple executions of the Procedure. To use the global variable to update the trial count, insert an InLine object as the first event in the trial Procedure, and enter script to increase the count.
The total trial count variable is updated simply by increasing the previous value by one (i.e., g_nTotalTrial+1). The second line of script referring to the c.SetAttrib command is used to place the value of g_nTotalTrial into an attribute (to make it accessible by other objects with the bracket notation and to log the value in the data file. Refer to GENERAL: Set or Reference Values in Script  for information pertaining to setting values as attributes.