This is an explanation of what the scripts in this folder exemplify.

--How to access the Time field of a Reaction Time. Very often, you will want to consult when something occurred during a trial. In order to do that, in PsyScope you have to take a Reaction Time, and then see at what moment the RT action occurred.

RT actions generate a complex record, and one of its field is the value you are interested in. You have to get to that damn field! In order to do that, the best solution I found is as follows

- Define a variable of type Response (say, you call it MyResp), and a variable of type Integer or Long Integer, or Real (say, you call it MyTime).

- Take a RT when you need, and assign it to MyResp.

- Now you can access the Time field with the syntax Myresp->time, and use this to assign the time value to MyTime.

The scripts show simple examples of how this can be achieved. The scripts do the following: Any time you press a key they take a RT; They shows that RT, plus the cumulative sum of all RTs you have taken so far; and they end the template containing the RT action on a mouse click and start a new template.

The ConditionalSingle script shows how you can do this by repeatedly taking RTs within one single, long lasting event. The ConditionalRepeated script shows how you can do it by using a short event that is repeated as many times as you want. The difference will be that in the first case, all your RTs will be taken starting from the beginning of that event, and hence will necessarily be increasingly higher values. In the second case instead, because the event ends and is being repeated several times, each RT will be aligned to the beginning of each repetition of that event, and hence the RT values will correspond to the actual time from one keypress to another.

--How to correctly save the Time field of a Reaction Time in the data file as a variable value. The scripts also show you how to solve another related problem.

Suppose you have assigned the time value of a RT to a variable, as explained above (call it MyTime). You now want to save that variable into the data file. The only way you have to write in the data file is to take a RT action. But the RT action you take is also the action you use to save a line of values in the data file! So for that line of values, the value of your variable will be systematically wrong, because you assign the value of the RT time filed to that variable after you have taken the RT! Not good.

Thanks to the fact that PsyScope X dynamically upgrades the values of variables within a single trial, you can now use a "trick" to solve this problem, by taking two RTs one after the other, as follows:

- You specify that the first RT should NOT to be saved in the data file.

-You then assign the value of that RT to your variable MyTime.

-Then, you take a second RT, which will be written in the data file.

This second RT will occur after the variable MyTime has received its value, and so it will have the right time value. Because both RTs and the value assignment occur within the same millisecond, the time value of the second RT will not change from that of the first, but the value of the MyTime variable will be the correct RT value. This correspond to write instructions like these in PsyScript:

Conditions[ End[] ] => Actions[ RT[ NULL NULL MyResp var_only ] set[MyTime "Myresp->time"] RT[] ]

where RT[ NULL NULL MyResp var_only ] takes a RT, assigns it to the variable Myresp (which is a response type variable), and it marks that the Rt should not be recorded in the data file. Then set[MyTime "Myresp->time"] assigns the time field of that response variable to the variable "MyTime" (which is of type integer, or long integer, or real), and the final RT gets the reaction time and writes the right values to the data files. NOTICE THAT THE ORDER OF THESE ACTIONS IS CRUCIAL.

You can run the scripts, and check the data file to see the relation between the "time" value and the value of your variables, to see that everything is right.

-- How to vary online properties of what comes next based on the RT of a preceding trial. The scripts are also useful to see how to solve another problem. Say you want to change the properties of a stimulus according to how fast a subject responded in a previous trial. For example, you want to say: if s/he was fast, make the next stimulus red. If s/he was slow, make it blue.

There are several ways to do that in PsyScope. The scripts show one of them which allow you to see how to properly use a simple function definition. The technique is simple:

-You use the same procedure as explained above in order to assign the value of the RT of an event to a numerical variable.

- Now you also script a function which uses that variable value.

The function must be added in the #> TrialManagerVariables part of the script. That function will say: If MyTime was more than a certain value, give "Blue" as a result; Otherwise, give "Red":

#> TrialManagerVariables

MyFunction:: Result: if(@MyTime>5000 "Blue" "Red")

Notice the syntax: MyFunction has to have a separate line with the Result: identifier. After it, you can write whatever you want -- expressions, numbers, operations. In this case, we write a logical expression. "Blue" and "Red" are strings of letters.

Finally, you use a function call as the value of the parameters of another event.

For simplicity, in the example, the event is a text event, that resides in another template, and we vary its color and its stimulus according to the value of that function:

Event4::

EventType: Text

Duration: key[Any] Mouse[ Click ]

Stimulus: MyFunction()

Color: MyFunction()

The important point to notice here is that the stimulus adn the color are a simple call to MyFunction, without arguments. The script will present the word "Blue" written in blue or the word "Red" written in red.