Set or Reference Values in Script
If variables are to be retrieved and/or logged, they must be placed into the experimental context as attributes (See GENERAL: Context . Otherwise, they exist only temporarily, and are discarded at the conclusion of the Procedure in which they are defined. Globally defined variables, created in the User Script window, are discarded when the Experiment Object terminates.
Attributes defined in a List object are automatically placed into the experimental context. For example, if a List object defines an attribute named “Stimulus ,” and the values of Stimulus are used to define the stimulus displayed during each trial, the value of Stimulus for each trial will automatically be logged in the data file.
In order to enter a temporary variable (e.g., g_nTotalTrial from the previous step) into the experimental context, either for the purpose of logging that value in the data file or for later access by another object, use the c.SetAttrib command. In the previous step, the value of the g_nTotalTrial variable was set as an attribute (i.e., c.SetAttrib “TrialCount,” g_nTotalTrial). The TrialCount attribute may then be accessed by another object using bracket notation, and the value of TrialCount will be logged in the data file.
The values of attributes and properties from the experimental context may also be accessed via script on an InLine object using the c.GetAttrib command. For example, the stimulus might display a random number selected from a range of values depending on the condition. “Condition” could be entered as a List attribute defining the possible conditions, and this value could be retrieved at runtime to set the possible range of values for the random number selection.
NOTE: The use of the “Else” condition in the script above. It is a good practice, and ultimately the programmer’s responsibility, to cover all possible conditions when writing script. If the values of the Condition attribute are carefully entered, the “Else” condition should not be necessary. However, it is better to consider the possibility of error than to have the program fail. Here, we put up a message box to tell the experimenter a bad stimulus condition has occurred.
The properties of objects may also be set or retrieved through script as long as the property is not read- only or design-time only (i.e., not able to be modified at runtime). For example, it is possible to vary messages presented at runtime based on the speed of the response collected. Such a procedure would require accessing one value (i.e., the reaction time from the input object Stimulus.RT), and setting another (i.e., the text to be displayed by the object presenting the message).
The GiveRTFeedback Inline object containing the script above sets the Text field for the WorkFaster TextDisplay object at runtime. Thus, no values need be entered for the Text field in the WorkFaster object in E-Studio.