In this post, I will describe, shortly, how to use InLine scripts in E-prime to save your data in comma-separated values (CSV) files. For those who are not familiar with E-prime, it is an experiment generating software based on visual basic (i.e., it has its own scripting language called e-basic). Its main purpose is to make building experiments easy/easier. It offers a drag-and-drop graphical user interface (GUI) which is fairly easy to use (although I prefer OpenSesame and PsychoPy – which both offer drag-and-drop GUIs). See the Wikipedia article if you want to know more about e-prime.
This guide will assume that you have worked with e-prime before. That is, you should already have a, more or less, ready experiment so you can add the scripts. In the guide, I use a Simon task created in e-prime as an example.
How to create a folder and a CSV file
I prefer to let the experimenter have the possibility to choose a name on the data file. Thus, we will start with creating a variable called experimentId (You may already know how to do this and can skip to the next part). We start by clicking on “Edit” in the menu and choosing “Experiment…”:
After doing this, we get the “Properties:Experiment Object Properties” dialog. From this dialog, we click on add:
In the next dialog, “Edit Startup Info Parameter”, we give our variable a name, experimentId (we type this in the “Log Name” field). In the “Prompt” field, we type in “Experiment ID”. This is what will show up when the experiment is started. We go on and change the Data Type to “String” and put “simonTask” as Default. This will be put in by default but can be changed by the experimenter.
Creating an InLine script
As previously mentioned, I assume you know how to create an experiment in e-prime, but I will briefly mention how to create an InLine script. Drag the object InLine from the “E-Objects” on the left of the GUI. I chose to put this in the “PracticeSimon” procedure, so it is one of the first things that is created when starting an experiment. I typically name the script “fileManagment” or something that clarifies what the script does.
' Sets up a data file On Error Resume Next MkDir "data_"+c.GetAttrib ("experimentId") ' Create the variable save of data type string and set save to current directory Dim save As String save = CurDir$ ' Change the directory to data_simonTask (since experimentId is by default simonTask) chdir("data_"+c.GetAttrib ("experimentId")) ' Create a file called data_simonTask if it does not exist If FileExists("data_"+c.GetAttrib ("experimentId")+".csv")=False Then Dim fileid As Integer fileid=freefile open "data_"+c.GetAttrib ("experimentId")+".csv" For output As #fileid print #fileid,"SubID;Date;Age;Sex;RT;ACC;CorrectResponse;Response;Arrows;TrialType" close End If chdir(save)Code language: VBScript (vbscript)
Note, the delimiter in the case above is “;”. That is, this makes whatever software you use later know where a new column begins. In this example, I want to store Subject ID (“SubID), the date, Age, Sex, Response Time (RT), Accuracy (ACC), and so on.
How to create an InLine script that saves data
Now that a data file and folder have been created, we can create an InLine script that saves the data (for each trial). In the Simon task example, I put the script (“saveData”) at the end of the “SimonTrial” procedure:
Responses, in the example, are logged in the “simonTarget”-object (an ImageDisplay object). However, we often want to save more information, such as what kind of trial it currently is. Such data is typically stored in a List object (List3 in the image above, for instance):
Now to the script that saves the data:
Dim save As String Dim fileid As Integer save = CurDir$ chdir("data_"+c.GetAttrib ("experimentId")) fileid=freefile open "data_"+c.GetAttrib("experimentId")+".csv" For append As #fileid ' "SubID;Date;Age;Sex;RT;ACC;CorrectResponse;simonTarget;TrialType" print #fileid,(c.GetAttrib("Subject"));";";Date;";";(c.GetAttrib("Age"));";";(c.GetAttrib("Sex"));";";(c.GetAttrib("simonTarget.RT"));";";(c.GetAttrib("simonTarget.ACC"));";";(c.GetAttrib("correct_resp"));";";(c.GetAttrib("simonTarget.Resp"));";";(c.GetAttrib("display2"));";";(c.GetAttrib("Type_C")) close chdir(save) doeventsCode language: VBScript (vbscript)
Note what is important in this script is that the data is stored in the order that we have created our column names. In the script above, we use the function c.GetAttrib(attribute) to get the current data stored in that variable. When we want to get the RT, we use (c.GetAttrib(“simonTarget.RT”) since this is where the responses are recorded. Startup info and information in the file can be accessed using only c.GetAttrib(). That was quite easy, right?!
There is one caveat, in your ImageDisplay object (i.e., in our case, simonTarget), we will have to set the prerelease to 0, or else we will not have anything recorded. This may sometimes be a problem (e.g., for timing and such). If anyone knows a solution to this, please let me know.