WEBVTT 00:00:01.132 --> 00:00:02.897 Hi. My name's John Pierce. 00:00:02.897 --> 00:00:04.347 I'm a lecturer at the University of Nottingham. 00:00:04.347 --> 00:00:07.430 I'm the inventor of PsychoPy. 00:00:07.430 --> 00:00:08.648 In this demo, I'll show you how to 00:00:08.648 --> 00:00:09.982 create a simple experiment in PsychoPy. 00:00:09.982 --> 00:00:11.829 We're going to use the Stroop effect. 00:00:11.829 --> 00:00:14.575 When you first start up PsychoPy, 00:00:14.575 --> 00:00:17.293 you'll find two windows come open: 00:00:17.293 --> 00:00:19.907 One is the builder view, which allows you to 00:00:19.907 --> 00:00:22.285 construct your experiments graphically. 00:00:22.285 --> 00:00:25.250 And the other is the coder view, which allows you to 00:00:25.250 --> 00:00:27.604 create your experiments using Python scripts 00:00:27.604 --> 00:00:29.802 if you prefer to write code directly. 00:00:29.802 --> 00:00:32.864 Today we're going to be using the builder view. 00:00:32.864 --> 00:00:37.052 The builder view has three panels. 00:00:37.052 --> 00:00:41.437 It's got components. It's got one or more routines. 00:00:41.437 --> 00:00:43.419 Here we've got a single routine called the "trial". 00:00:43.419 --> 00:00:45.809 And it's got a flow which allows you to 00:00:45.809 --> 00:00:51.985 combine multiple routines together. 00:00:51.985 --> 00:00:53.780 In the case of the Stroop task, we'll need a 00:00:53.780 --> 00:00:56.300 a text object as part of our trial 00:00:56.300 --> 00:00:58.279 because we need to present a word to the subjects. 00:00:58.279 --> 00:01:00.521 So, let's create a text object. 00:01:00.521 --> 00:01:03.869 We'll call it "target". We'll have it start at 00:01:03.869 --> 00:01:06.107 maybe naught point five seconds, 00:01:06.107 --> 00:01:09.127 and it will last for five seconds. 00:01:09.127 --> 00:01:11.626 Notice that each of these parameters, 00:01:11.626 --> 00:01:14.036 as I hover my mouse over them, it gives me a tip to 00:01:14.036 --> 00:01:18.440 inform me about what I would be expected to include. 00:01:18.440 --> 00:01:21.366 There's also a help button. If I click on that, 00:01:21.366 --> 00:01:24.379 I'll go to the PsychoPy web site where it will tell me 00:01:24.379 --> 00:01:27.181 more detailed information about how to use 00:01:27.181 --> 00:01:29.760 this particular component. 00:01:29.760 --> 00:01:33.182 For now, we're not going to set color and the text 00:01:33.182 --> 00:01:36.763 of this text object. We'll come back to that 00:01:36.763 --> 00:01:39.292 later on. 00:01:39.292 --> 00:01:42.700 Having hit "OK", we can see the text object 00:01:42.700 --> 00:01:45.556 appearing in our routine and if we want to edit 00:01:45.556 --> 00:01:48.177 that, we can click on the icon again and we 00:01:48.177 --> 00:01:50.975 can get back and change our stimulus. 00:01:50.975 --> 00:01:53.857 Maybe we want it to be for four seconds, instead of for five. 00:01:53.857 --> 00:01:56.734 So it's now changed that representation. 00:01:56.734 --> 00:02:01.224 We also, for the Stroop task, need for the 00:02:01.224 --> 00:02:04.333 subjects to respond. So let's add a keyboard 00:02:04.333 --> 00:02:09.952 to this routine. We'll call it "response". 00:02:09.952 --> 00:02:13.465 We'll also start that at naught point five seconds. 00:02:13.465 --> 00:02:14.617 We don't want subjects to respond before 00:02:14.617 --> 00:02:17.176 the target was presented. 00:02:17.176 --> 00:02:21.162 I'm going to set this to have an infinite duration. 00:02:21.162 --> 00:02:24.342 If we set that to be blank, then the keyboard 00:02:24.342 --> 00:02:26.519 will be available forever. 00:02:26.519 --> 00:02:30.444 We're going to leave the allowed keys for now. 00:02:30.444 --> 00:02:32.394 I'll come back and change those later on, 00:02:32.394 --> 00:02:34.183 once we've set up our trials. 00:02:34.183 --> 00:02:41.268 OK, now we that the response is going to 00:02:41.268 --> 00:02:43.097 last forever. 00:02:43.097 --> 00:02:47.387 So, that's roughly what one trial is going to look like 00:02:47.387 --> 00:02:50.182 in the Stroop task. But we need to run more 00:02:50.182 --> 00:02:52.221 than one trial and right now we've got that 00:02:52.221 --> 00:02:54.453 routine appearing just once on our flow. 00:02:54.453 --> 00:02:57.761 Let's insert a loop around the trial, 00:02:57.761 --> 00:03:00.414 so that we can repeat it. 00:03:00.414 --> 00:03:02.569 If I click on "Insert loop" just once, 00:03:02.569 --> 00:03:05.299 and select, again with a single click, 00:03:05.299 --> 00:03:08.597 where we want our loop to start and stop. 00:03:08.597 --> 00:03:12.637 It brings up a dialog box, asking me 00:03:12.637 --> 00:03:14.557 what do I want to call this loop. 00:03:14.557 --> 00:03:16.414 We'll call it "trials". That's fine. 00:03:16.414 --> 00:03:21.448 Should it be random or sequential in choosing the next condition? 00:03:21.448 --> 00:03:22.961 Random is fine. 00:03:22.961 --> 00:03:25.686 We'll have five repeats, and we need to 00:03:25.686 --> 00:03:27.573 go and specify our conditions file. 00:03:27.573 --> 00:03:30.134 Now, you'll notice here it's asking for a trial 00:03:30.134 --> 00:03:33.963 a file that's CSV or XLSX. We need to go off 00:03:33.963 --> 00:03:36.485 to Excel in order to create our file. 00:03:36.485 --> 00:03:40.418 And click "OK". You'll see it insert the 00:03:40.418 --> 00:03:42.509 loop around the trial. 00:03:42.509 --> 00:03:45.481 Let's go and save that experiment now, 00:03:45.481 --> 00:03:47.937 so that we don't lose it. 00:03:47.937 --> 00:03:53.579 Save. I'm going to create a new folder on 00:03:53.579 --> 00:04:00.620 my desktop called "Stroop" and maybe I'll 00:04:00.620 --> 00:04:05.142 call the file "Stroop Experiment". 00:04:05.142 --> 00:04:09.026 Okay. 00:04:09.026 --> 00:04:14.455 The easiest way to define the conditions for 00:04:14.455 --> 00:04:18.914 your experiment is to use a spreadsheet package 00:04:18.914 --> 00:04:20.360 like Excel. 00:04:20.360 --> 00:04:22.461 We can create a number of parameters for 00:04:22.461 --> 00:04:25.397 our experiment, such as the word that we're 00:04:25.397 --> 00:04:27.803 going to present, or the color that it will 00:04:27.803 --> 00:04:30.862 be presented in, and we can create a number 00:04:30.862 --> 00:04:34.064 of different conditions. We specify one on each row. 00:04:34.064 --> 00:04:38.328 So, for the Stroop task, we might use the word "red" 00:04:38.328 --> 00:04:43.789 written in red. We might have the word "red" written 00:04:43.789 --> 00:04:48.140 in green. We might have the word "green" 00:04:48.140 --> 00:04:51.279 written in green, etc. 00:04:51.279 --> 00:05:04.370 "Green" in blue. "Blue" blue. "Blue" and red. 00:05:04.370 --> 00:05:08.024 I'm going to keep track of whether or not 00:05:08.024 --> 00:05:10.101 those are congruent. We don't really need to do this. 00:05:10.101 --> 00:05:12.668 We could always work it out later, but it's 00:05:12.668 --> 00:05:15.548 kind of convenient to have that stored as well. 00:05:15.548 --> 00:05:17.631 So, congruent and I'm going to say "1"; 00:05:17.631 --> 00:05:20.634 that means "true"; and "0" for "false". 00:05:20.634 --> 00:05:25.364 That's just going to help us later on. 00:05:25.364 --> 00:05:28.066 Now we also need to specify what's the 00:05:28.066 --> 00:05:30.575 correct answer, cause PsychoPy will want to know 00:05:30.575 --> 00:05:33.663 whether or not the subject got it right or wrong. 00:05:33.663 --> 00:05:39.719 I'm going to call that "corrAns". 00:05:39.719 --> 00:05:43.766 These parameters can't use any punctuation 00:05:43.766 --> 00:05:47.543 or spaces in their names. So, I'm going to 00:05:47.543 --> 00:05:50.577 take away the space and give it a capital letter 00:05:50.577 --> 00:05:53.960 for, uh, to specify the correct answer. 00:05:53.960 --> 00:05:57.335 In this case, we're going to use the left, 00:05:57.335 --> 00:06:02.103 down, and right cursor keys from the keyboard. 00:06:02.103 --> 00:06:05.709 So, I'm going to specify that red -- and remember 00:06:05.709 --> 00:06:08.301 in the Stroop task that the subjects are asked 00:06:08.301 --> 00:06:10.781 to report the color of the text rather than 00:06:10.781 --> 00:06:14.086 the word itself. So, when the color is red, I'm 00:06:14.086 --> 00:06:15.898 going to ask the subjects to press "left". 00:06:15.898 --> 00:06:19.152 That's the left cursor key. 00:06:19.152 --> 00:06:20.931 When it's green they should press "down". 00:06:20.931 --> 00:06:23.428 "Down" again. 00:06:23.428 --> 00:06:26.351 When the color's blue they should press "right". 00:06:26.351 --> 00:06:28.294 "Right". 00:06:28.294 --> 00:06:31.965 And now I've got red again, so they should 00:06:31.965 --> 00:06:32.973 press "left". 00:06:32.973 --> 00:06:35.811 Okay, that defines six different conditions 00:06:35.811 --> 00:06:38.616 for our experiment with four different parameters. 00:06:38.616 --> 00:06:41.480 Okay, let's save that file. 00:06:41.480 --> 00:06:47.119 I'm going to put it in the same folder as my 00:06:47.119 --> 00:06:49.467 experiment, although you don't have to. 00:06:49.467 --> 00:06:52.789 And I'm going to call it "conditions.xlsx". 00:06:52.789 --> 00:06:54.440 It's very important that you save it 00:06:54.440 --> 00:06:58.250 in the XLSX format. PsychoPy can't use the old 00:06:58.250 --> 00:07:02.468 XLS style spreadsheets. 00:07:02.468 --> 00:07:07.695 Click "Save" and we're done. 00:07:07.695 --> 00:07:11.758 So now we need to show PsychoPy where that file 00:07:11.758 --> 00:07:14.364 is, and how to use it during the trials. 00:07:14.364 --> 00:07:18.557 The way to do that is with the loop dialog. 00:07:18.557 --> 00:07:21.831 So, if I just click on that loop again, 00:07:21.831 --> 00:07:24.559 we'll get the properties back for the loop 00:07:24.559 --> 00:07:27.308 and there's a conditions file. If we browse, 00:07:27.308 --> 00:07:31.306 we can select our file that we've just created, 00:07:31.306 --> 00:07:37.468 open that, and it's told me that there are 00:07:37.468 --> 00:07:40.055 six conditions with four different parameters. 00:07:40.055 --> 00:07:41.618 The parameters are color, word, congruent 00:07:41.618 --> 00:07:43.452 and correct answer. 00:07:43.452 --> 00:07:47.662 Ok? If the file had been invalid in some way, 00:07:47.662 --> 00:07:49.665 maybe we had a space in one of our column 00:07:49.665 --> 00:07:52.212 headings, then we would get a warning here to 00:07:52.212 --> 00:07:54.216 say that we couldn't use that file or it 00:07:54.216 --> 00:07:56.612 wouldn't show us the parameters were there. 00:07:56.612 --> 00:07:59.880 Now we can select "OK". It's showing that we've 00:07:59.880 --> 00:08:05.294 got five times six random trials. 00:08:05.294 --> 00:08:09.788 So, five different repeats of six different conditions. 00:08:09.788 --> 00:08:14.637 Okay, so the conditions file is now being set 00:08:14.637 --> 00:08:17.054 here on each repeat through the loop, we use 00:08:17.054 --> 00:08:18.378 a different row. 00:08:18.378 --> 00:08:21.315 We still need to tell the stimulus about the 00:08:21.315 --> 00:08:24.035 parameters that it needs to use. 00:08:24.035 --> 00:08:26.312 We want the color of our stimulus to be set 00:08:26.312 --> 00:08:31.243 by that color parameter. Now, I've typed in 00:08:31.243 --> 00:08:35.336 "$colour" here, spelt with a "u" because that's 00:08:35.336 --> 00:08:38.028 how we spelt it in the Excel file. 00:08:38.028 --> 00:08:42.931 And that "$" is to tell PsychoPy "This isn't a 00:08:42.931 --> 00:08:45.845 literal value. It's a variable." 00:08:45.845 --> 00:08:47.767 Okay? So, it's going to go off and find a 00:08:47.767 --> 00:08:50.173 variable called "colour" and see what the current 00:08:50.173 --> 00:08:52.200 value of that variable is. 00:08:52.200 --> 00:08:54.164 It's going to be red or green or blue. 00:08:54.164 --> 00:08:58.678 I'm also going to set that to change on every repeat 00:08:58.678 --> 00:09:01.493 rather than being constant. 00:09:01.493 --> 00:09:03.436 Okay? We don't want the stimulus just to be 00:09:03.436 --> 00:09:07.220 fixed to one particular color for the entire experiment. 00:09:07.220 --> 00:09:11.238 Similarly, the text of this text stimulus should be 00:09:11.238 --> 00:09:15.916 the word that we've specified in the Excel file 00:09:15.916 --> 00:09:19.457 and it shouldn't be "word" it should be the variable 00:09:19.457 --> 00:09:22.394 "word" in order to go and fetch that variable 00:09:22.394 --> 00:09:24.506 which is going to be red or green or blue. 00:09:24.506 --> 00:09:29.034 And, again, we want that to change on every repeat 00:09:29.034 --> 00:09:31.091 of this routine. 00:09:31.091 --> 00:09:40.656 Okay. We also need to set the response to be 00:09:40.656 --> 00:09:44.970 based on the conditions. So I need to change 00:09:44.970 --> 00:09:47.391 the keys that are going to be allowed for 00:09:47.391 --> 00:09:49.464 the subject to respond with. We don't want them 00:09:49.464 --> 00:09:52.128 to use the "yes" or the "no". We want them to use 00:09:52.128 --> 00:09:57.230 "left", "right" and "down". So, notice that any keys 00:09:57.230 --> 00:10:00.581 I want to put here I separate by commas and 00:10:00.581 --> 00:10:05.026 I have to put inverted commas around the names 00:10:05.026 --> 00:10:07.494 of each of the keys. 00:10:07.494 --> 00:10:11.775 If I leave that blank -- the entire box -- then all keys 00:10:11.775 --> 00:10:14.809 will be available. Okay? So that allows the subject 00:10:14.809 --> 00:10:19.724 to press any key. I've also got "forceEndRoutine" 00:10:19.724 --> 00:10:22.765 checked here. We left the response to be 00:10:22.765 --> 00:10:26.222 infinite but as soon as they press any key, 00:10:26.222 --> 00:10:28.205 it will force the end of that trial. 00:10:28.205 --> 00:10:30.271 So that's a useful thing for us to do. 00:10:30.271 --> 00:10:32.813 We're also going to want to store correct. 00:10:32.813 --> 00:10:36.512 So, if I check that box, we have to tell PsychoPy 00:10:36.512 --> 00:10:39.030 what is the correct answer on this trial, 00:10:39.030 --> 00:10:43.857 and if you remember, that was stored as "corrAns". 00:10:43.857 --> 00:10:48.495 Again, we need to use "$corrAns" to specify 00:10:48.495 --> 00:10:52.550 the fact that this is a variable name not, 00:10:52.550 --> 00:10:54.919 it shouldn't be looking for a key called "corrAns" 00:10:54.919 --> 00:10:56.542 cause it will never find one. It's got to use 00:10:56.542 --> 00:11:00.997 the variable "corrAns". And that's us done. Okay. 00:11:00.997 --> 00:11:06.868 Save. Okay, we're pretty much there. 00:11:06.868 --> 00:11:09.619 That should be a working experiment, but we do also 00:11:09.619 --> 00:11:12.094 want to provide the subject with some instructions. 00:11:12.094 --> 00:11:15.383 I'm going to insert another routine into the flow. 00:11:15.383 --> 00:11:20.543 When I click that button it shows me either "new" 00:11:20.543 --> 00:11:24.298 or "trial". Let's select "new" and I'll call it 00:11:24.298 --> 00:11:31.254 "instructions"... if I can spell it. "Instructions". 00:11:31.254 --> 00:11:35.553 It asks where I want to insert the instructions. 00:11:35.553 --> 00:11:38.139 We don't want it to be here because that would 00:11:38.139 --> 00:11:40.016 repeat the instructions on every trial. 00:11:40.016 --> 00:11:43.980 Let's put it before the loop. And now we can click 00:11:43.980 --> 00:11:48.576 on the instructions routine and we can edit that. 00:11:48.576 --> 00:11:52.340 So, we're going to want another text object. 00:11:52.340 --> 00:12:02.253 We're going to call that, say, "instrText", 00:12:02.253 --> 00:12:05.829 start at time zero. Duration, we'll make it infinite. 00:12:05.829 --> 00:12:11.737 Color white, that's fine. And we'll give it the text 00:12:11.737 --> 00:12:27.509 "Remember choose the color of the letters, 00:12:27.509 --> 00:12:33.696 ignoring the word: 00:12:33.696 --> 00:12:46.957 left = red, down = green, right = blue. 00:12:46.957 --> 00:12:49.035 Okay. 00:12:49.035 --> 00:12:54.680 Now because we've made that text last forever, 00:12:54.680 --> 00:12:56.465 we gave it an infinite duration, we need to make 00:12:56.465 --> 00:12:59.016 sure that the subject can get rid of them. 00:12:59.016 --> 00:13:05.412 So, we'll click on a keyboard, we'll allow any key, 00:13:05.412 --> 00:13:10.151 we'll force the end of the routine, and we won't 00:13:10.151 --> 00:13:12.890 bother storing anything. 00:13:12.890 --> 00:13:15.799 We make that last forever. 00:13:15.799 --> 00:13:18.192 Okay. 00:13:18.192 --> 00:13:23.540 If you do get that wrong, you should always be able 00:13:23.540 --> 00:13:25.855 to hit "escape" and you will still be able to quit 00:13:25.855 --> 00:13:27.442 the experiment without having to 00:13:27.442 --> 00:13:28.735 restart your computer. 00:13:28.735 --> 00:13:31.079 Okay, I'm going to save that again. 00:13:31.079 --> 00:13:32.589 I think we're done. 00:13:32.589 --> 00:13:37.067 Okay, let's just have a quick look at the 00:13:37.067 --> 00:13:39.364 Experiment Settings dialog box. 00:13:39.364 --> 00:13:42.300 In this dialog, you can control things like whether 00:13:42.300 --> 00:13:45.123 or not the mouse is visible during the experiment, 00:13:45.123 --> 00:13:48.133 the color of the background of the screen, 00:13:48.133 --> 00:13:51.420 whether or not it's in a window or in full screen, 00:13:51.420 --> 00:13:54.463 is it "screen 1" or "screen 2" if you've got 00:13:54.463 --> 00:13:57.029 multiple monitors, and what sort of data files 00:13:57.029 --> 00:13:59.560 you want to save out. So, lots of useful things there 00:13:59.560 --> 00:14:01.869 to control your experiment. 00:14:01.869 --> 00:14:05.355 Now, at this point we could construct a script. 00:14:05.355 --> 00:14:08.771 That'll allow you to go off and maybe learn a little 00:14:08.771 --> 00:14:15.104 bit about how Python works. It's about 220 lines 00:14:15.104 --> 00:14:18.279 long, this particular experiment. So, not too 00:14:18.279 --> 00:14:21.785 complicated a script. But we don't need to. 00:14:21.785 --> 00:14:24.826 We could actually go off and run our experiment 00:14:24.826 --> 00:14:26.926 by hitting the green man. 00:14:26.926 --> 00:14:31.149 Often takes a few seconds, especially the first time 00:14:31.149 --> 00:14:34.740 you run. So, be patient with that one. 00:14:34.740 --> 00:14:36.785 There we go. We've got a dialog box come up 00:14:36.785 --> 00:14:39.596 asking for the participant and the session number. 00:14:39.596 --> 00:14:42.103 That was also being controlled in the Experiment 00:14:42.103 --> 00:14:43.712 Settings dialog. 00:14:43.712 --> 00:14:45.359 I'm not actually going to run the experiment. 00:14:45.359 --> 00:14:47.964 I'll leave that to you. 00:14:47.964 --> 00:14:49.795 Okay. Have you found that useful? 00:14:49.795 --> 00:14:51.821 Check out the Demos menu for more ideas 00:14:51.821 --> 00:14:54.000 and I hope you enjoy using PsychoPy!