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