This sample illustrates the use of global variables and an array to record the median response time of correct trials answered by the subject.
In the User script, a Summation object is created to log the overall accuracy of the trials. A dynamic array is declared to hold the number of correct response times.
An InLine object called 'Init' sets up the Summation object. This experiment uses the entire "0" based array. For that reason, the size of the array is defined as 'TrialList.Size minus 1'.
The 'AssignVals' InLine object checks the response accuracy. If the trial is correct, the response time is logged as an array value. If it is incorrect, the size of the dynamic array is decreased. This is done to prevent logging a value of "0" for the median. When the size of the array object is decreased, the "Preserve" keyword is used to prevent the data from being erased in the array.
In the 'Sort' InLine object, the "ArraySort" statement is used to sort the array in ascending order. The "Mod" function is used to check the number of trials that were logged in the array. If there is an odd number of items in the array, the array is divided by 2 to find the median. If there is are even number of items in the array, integer division is used. Then the two arrays are added together and divided by 2 to get the average.