Introduction

Sometimes you want to give people more time to respond to a stimulus than the stimulus is present.

In other words, sometimes you want that a stimulus disappears while you are waiting for a keypress.

This tutorial shows this.

For an actual experiment using this technique, see for example the N-back experiment in the experiment library.

First run this very simple experiment to see what it does. Note that you need to respond to the smiley face. The smiley face disappears but you can press the button longer.

The PsyToolkit code

bitmaps  (1)
  text_still_waiting  (2)
  press_the_key
  well_done
  time_is_up
  frame
  smiley

fonts  (3)
  arial 18  (4)

task disappear  (5)
  keys b  (6)
  draw off  (7)
    show bitmap frame  (8)
    show bitmap press_the_key 0 -200 (9)
    show bitmap smiley (10)
  draw on  (11)
  readkey 1 500 (12)
  clear 3  (13)
  set $tmp_rt RT  (14)
  set $tmp_status STATUS  (15)
  set $total_rt RT  (16)
  if STATUS == TIMEOUT  (17)
    show bitmap text_still_waiting 0 215  (18)
    readkey 1 4500  (19)
    clear -1  (20)
    set $total_rt expression RT + $tmp_rt  (21)
  fi  (22)
  if STATUS == 1  (23)
    show bitmap well_done  (24)
    delay 1500  (25)
    clear -1  (26)
    show text "Reaction time in milliseconds:" -100 0   0 255 0  (27)
    show text $total_rt  100 0   0 255 0  (28)
    delay 1500  (29)
    clear -1 -2  (30)
  fi  (31)
  if STATUS == TIMEOUT   (32)
    show bitmap time_is_up  (33)
    delay 1500  (34)
    clear -1  (35)
  fi  (36)
  save $tmp_rt $tmp_status $total_rt STATUS  (37)

block test  (38)
  tasklist  (39)
    disappear 20  (40)
  end  (41)
1 In the bitmaps section, you tell the computer the names of the bitmaps (assuming these are PNG bitmap files)
2 There is a bitmap file text_still_waiting which is a bitmap of a nice green text (sometimes it is nicer to make texts in the form of a bitmap, because then you can use nice fonts and so on, it gives you a bit more control
3 In the fonts section, you tell the computer which fonts you use.
4 In this experiment, we use only one font, size 18 points, for showing the reaction time
5 You can have one or more task sections. You need to give the task a name, I called it "disappear", but you can choose any name here
6 You tell the computer that this experiment uses one keyboard key, people need to press the kbd:[b] later on in the experiment. But at the beginning, you need to say which keys are being used with the "keys" instruction
7 If you want to show multiple stimuli at the same time, you can put them between draw off and draw on. This ensures they all appear exactly at the same time (you can also leave this instruction out, which looks almost the same, but this is better for fast presentation of multiple stimli.
8 The first stimulus is a bitmap called "frame". There is a bitmap frame.png, as defined in the bitmaps section. We do not give the X/Y position of the stimulus, which means it will be presented exactly in the middle of the screen.
9 The bitmap press_the_key (as defined above in the bitmaps section), is shown at X/Y position 0 (that is central) and -200 (which is 200 pixels above the screen center).
10 We show a green smiley bitmap
11 With draw on we tell the computer that all the stimuli since the last draw off should now be shown all at once.
12 With this readkey, we tell the computer to wait for the first key in the keys instruction (there is only one, namely the kbd:[b]), and that we will wait maximaly 500 ms
13 As soon as the participant has pressed the button (or if not pressed, after 500 ms), the third stimulus shown will be cleared from the screen. Note that every time you have a show instruction, each shown stimulus gets a number. You can clear stimuli using this number.
14 The readkey results in two standard variables used by PsyToolkit, namely RT and STATUS. With set, we now store the value of the RT in a variable which I named $tmp_rt. Note that the dollar sign tells the computer this is a "local" variable. A local variable is a variable that will be set to 0 at the beginning of the task.
15 Similarly, we store the STATUS of the readkey instruction in a temporary variable. Note that the set instruction is used to set the value of variables. The STATUS can be CORRECT, WRONG, or TIMEOUT. You can probably guess what they mena.
16 We also create a new variable that ultimately will hold the total response time. Right now it contains just the same value. Later you will understand why this is being done.
17 Now we get an if instruction. The following lines until fi are only done if STATUS == TIMEOUT_. That is, if the person did not press a button we have a timeout.
18 Now, the timeout was not really a mistake in this specific experiment! We show the image telling the participant they can still press the button
19 Now we wait again for a key. This is basically the second part of still checking the same response to the stimulus, but now the smiley is no longer on screen. Normally you would not have such a message, but this is just a tutorial demonstration, so I just wanted to make sure you know here you can still press the kbd:[b] key. Now we wait up to 4500 milliseconds (that is 4.5 seconds).
20 We now remove the text bitmap underneath the frame.
21 This is important. Now we set the variable $total_rt to the last RT + the one we already had (which will by definition be 500 ms, because they would have been a timeout — in case of a timeout, the RT is set to the maximum value).
22 This indicates the end of the if section we just had.
23 Another if instruction. The following lines up to fi will only be done if the STATUS of the last readkey instruction was correct. You could also have typed if STATUS == CORRECT, but the numerical value of a CORRECT response just happens to be 1 (that is just a PsyToolkit convention)
24 We show a bitmap with a postive "well done" message in our special nice font (that is why we use a bitmap instead of a show text instruction
25 With delay, we make sure the last shown bitmap stays on screen for 1500 ms (1.5 second) before it is removed (next point)
26 Then we clear it from the screen. The -1 just means that we want to remove the last shown bitmap. This is handy, because this way you do not need a count of all the stimuli shown so far.
27 With show text, we now create a text stimulus. The -100 0 is the X/Y position (that is 100 pixels left from screen center). The 0 255 0 is the RGB color of the text. This means we have 0 red, 255 green, and 0 blue, which gives you a bright green stimulus.
28 Again another text, now we display the variable $total_rt, which is the reaction time.
29 We wait 1500 ms.
30 Now we remove the last two stimuli shown (the two texts).
31 Now we end the if section we just had
32 Our final if line. The following line are done if the STATUS is again TIMEOUT. This means the participant did not respond when the smiley was visible and not afterwards. We gave altoghether 5000 ms (500 for the first readkey and 4500 for the second readkey instruction)
33 We show the bitmap telling the participant the time is up
34 We show that bitmap for 1500 ms
35 We remove the last shown bitmap from screen
36 This indicates the end of the last if block.
37 Finally, we save our data. Really useful of those are the total reaction time, $total_rt, and the last STATUS (which will be 1 or 3, correct, or timeout.
38 Now we start our block. Each block needs to have a name, here it is unoriginally "test"
39 The tasklist tells the computer which tasks need to be done.
40 We run the task disappear 20 times
41 The tasklist needs to be closed off with end.