forked from tierneylee98/ESST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ESST.html
1005 lines (941 loc) · 47.4 KB
/
ESST.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!---Coded and designed by Tierney Lee, Becky Gilbert, Maris Vainre, and Marc Bennett, 2021--->
<!DOCTYPE html>
<html>
<head>
<title>Emotional stop signal task</title>
<script src="jspsych/jspsych.js"></script>
<script src="jspsych/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych/plugins/jspsych-image-keyboard-response.js"></script>
<script src="jspsych/plugins/jspsych-instructions.js"></script>
<script src="jspsych/plugins/jspsych-fullscreen.js"></script>
<script src = "jatos.js"></script>
<script src = "js/jquery.min.js" type="text/javascript"></script>
<script src = "js/block_trials/block1_info.js"></script>
<script src = "js/block_trials/block2_info.js"></script>
<script src = "js/block_trials/block3_info.js"></script>
<script src = "js/block_trials/practice_info.js"></script>
<link href="css/SwellStyle_dark.css" rel="stylesheet" type="text/css"></link>
</head>
<body style="background-color:black;"></body>
<script type="text/javascript">
// no-go stimulus image path
var stop_image = 'img/ESST/signals/stop_signal.bmp';
//set up fixation
var fixation_image = 'img/ESST/signals/fixpoint.png';
//set up feedback images
var correct_image = 'img/ESST/signals/correct.bmp'
var wrong_image = 'img/ESST/signals/incorrect.bmp'
//set up SSD
var delay = 250;
//set up trial counts
var trial_absolute_count = 1;
var practice_within_count = 1;
var practice_go_count = 1;
var practice_stop_count = 1;
var block1_within_count = 1;
var block1_go_count = 1;
var block1_stop_count = 1;
var block2_within_count = 1;
var block2_go_count = 1;
var block2_stop_count = 1;
var block3_within_count = 1;
var block3_go_count = 1;
var block3_stop_count = 1;
// set up durations
var feedback_duration = 500;
var feedback_trial_gap_duration = 1000;
var fixation_duration = 500;
var IAPS_duration = 1000;
var IAPS_gap_duration = 1000;
var stopStim_duration = 500;
var stopStim_post_trial_gap_duration = 1000;
var goStim_duration = 1000;
var goStim_post_trial_gap_duration = 500;
// set up block trial data
var practice_trial_info = practice_info;
var randomize_block_trials = jsPsych.randomization.shuffle([block1, block2, block3]);
var block1_trial_info = jsPsych.randomization.shuffle(randomize_block_trials[0]);
var block2_trial_info = jsPsych.randomization.shuffle(randomize_block_trials[1]);
var block3_trial_info = jsPsych.randomization.shuffle(randomize_block_trials[2]);
//set up timeline
var timeline = [];
// make the experiment to be fullscreen to avoid distractions
timeline.push({
type: 'fullscreen',
fullscreen_mode: true
});
// see docs for more info on the instructions plugin: https://www.jspsych.org/plugins/jspsych-instructions/
var welcome = {
type: "html-keyboard-response",
stimulus: "<h1>Welcome!</h1>" +
"<p>Thank you for taking your time to participate in this study! </p><h2>Press any key to start</h2>"
};
timeline.push(welcome);
var instructions1 = {
type: 'instructions',
pages: ["<h1>Get settled in for the next 20 minutes</h1>" +
"<p>Make sure you're <b>sitting comfortably</b>.<br><br><h1>🔕</h1><p>Shield yourself from <b>distractions</b>: <br>📴 <b>mute</b> your phone and <br>📩 e-mail alerts </p>" +
"<h2><br>Ready? Press space to continue</h2>"],
key_forward: 32, // code for space
show_clickable_nav: false
};
timeline.push(instructions1);
var instructions2 = {
type: 'instructions',
pages: [
"<p>You will see a photograph followed by an arrow.<br>The arrows may point to the left or to the right.</p><h1>⬅ ➡</h1>"+
"<h2><br>Press space to continue</h2>",
"<h1>⬅</h1><p>If the arrow is pointing to the left, then you should press the C-key.</p>" +
"<br><h1>➡</h1><p>If the arrow is pointing to the right, then you should press the N-key.</p>"+
"<h2><br>Press space to continue</h2>",
"<h1>⬆</h1>"+
"<p>Sometimes, the left/right arrow will be followed by an <b>arrow pointing upwards</b>.</p>" +
"<p>When this happens</p><h4>🚫 YOU MUST NOT RESPOND</b>🚫</h4><p>no matter if the arrow before was pointing to the left or to the right</p>" +
"<h2><br>Press space to continue</h2>",
"<h1>⏱</h1>"+
"<h2>Try to be <b>as quick as possible</b> in your responses</h2>"+
"<p>To make it faster, <br>put your left index finger on the C-key and <br>your right index finger on the N-key.</b></p>"+
"<h2><br>Press space to continue</h2>",
"<h1>🔁</h1><p>First, let's practice this.<br>We'll give you feedback on how you're doing.</p>" +
"<h2><br>Ready? Press space to start the practice</h2>"
],
key_forward: 32, // code for space
show_clickable_nav: false
};
timeline.push(instructions2);
// set up feedback and conditions for practice trials
var too_slow_message = {
type: 'html-keyboard-response',
stimulus: '<h1 style="color:#ef476f;">Please respond faster</h1>',
choices: jsPsych.NO_KEYS,
trial_duration: feedback_duration,
post_trial_gap: feedback_trial_gap_duration,
data: {trial_segment: 'too_slow'}
}
var too_slow_conditional = {
timeline: [too_slow_message],
conditional_function: function() {
var last_trial_data = jsPsych.data.get().last(1).values()[0];
if (last_trial_data.trial_segment == "target") {
return true;
} else {
return false;
}
}
}
var practice_correct_go = {
type: 'image-keyboard-response',
stimulus: correct_image,
choices: jsPsych.NO_KEYS,
trial_duration: feedback_duration,
post_trial_gap: feedback_trial_gap_duration,
data: {trial_segment: 'practice_correct_go'}
}
var practice_correct_go_conditional = {
timeline: [practice_correct_go],
conditional_function: function() {
var last_trial_data = jsPsych.data.get().last(1).values()[0];
if (last_trial_data.trial_response == last_trial_data.trial_response_correct) {
return true;
} else {
return false;
}
}
}
var practice_wrong_go = {
type: 'image-keyboard-response',
stimulus: wrong_image,
choices: jsPsych.NO_KEYS,
trial_duration: feedback_duration,
post_trial_gap: feedback_trial_gap_duration,
data: {trial_segment: 'practice_wrong_go'}
}
var practice_wrong_go_conditional = {
timeline: [practice_wrong_go],
conditional_function: function() {
var last_trial_data = jsPsych.data.get().last(1).values()[0];
if (last_trial_data.key_press !== null && last_trial_data.trial_response !== last_trial_data.trial_response_correct) {
return true;
} else {
return false;
}
}
}
var practice_correct_stop = {
type: 'image-keyboard-response',
stimulus: correct_image,
choices: jsPsych.NO_KEYS,
trial_duration: feedback_duration,
post_trial_gap: feedback_trial_gap_duration,
data: {trial_segment: 'practice_correct_stop'}
}
var practice_correct_stop_conditional = {
timeline: [practice_correct_stop],
conditional_function: function() {
var last_trial_data = jsPsych.data.get().last(1).values()[0];
if (last_trial_data.correct == true) {
return true;
} else {
return false;
}
}
}
var practice_wrong_stop = {
type: 'image-keyboard-response',
stimulus: wrong_image,
choices: jsPsych.NO_KEYS,
trial_duration: feedback_duration,
post_trial_gap: feedback_trial_gap_duration,
data: {trial_segment: 'practice_wrong_stop'}
}
var practice_wrong_stop_conditional = {
timeline: [practice_wrong_stop],
conditional_function: function() {
var last_trial_data = jsPsych.data.get().last(1).values()[0];
if (last_trial_data.trial_segment !== "stop_signal") {
return false;
} else {
return true;
}
}
}
// Gets triggered when no keyboard response has made for the last 3 trials where response is needed. The trial is paused and will continue when space is pressed.
var instructions_break1 = {
type: 'instructions',
pages: ["<h1>Need a break?</h1>" +
"<p>Have a good stretch if so.</p>" +
"<h2><br>Press space when you're ready to continue</h2>"],
key_forward: 32, // code for space
show_clickable_nav: false
};
var display_haveabreak_message_conditional = {
timeline: [instructions_break1],
conditional_function: function() {
if (trial_absolute_count > 10) {
var trial_totalmisses = jsPsych.data.get().filter({trial_segment: 'target', key_press: null}).count(); // this is just to test the function in console. It has no functionality for the function and can be deleted.
var trial_last3matches = jsPsych.data.get().filter({trial_segment: 'target'}).last(3); // count the last 3 trials that are matches (ie where keypress is needed):
var trial_last3matches_misses = trial_last3matches.filter({key_press: null}).count(); // count the number of times where there were no keypress (a proxy that the participant may not be paying attention);
console.log('trials misses ' + trial_totalmisses + ' out of ' + trial_absolute_count + ' trials. Number of trials missed in the last 3: ' + trial_last3matches_misses);
if (trial_last3matches_misses == 4) { // gets triggered if missed at least 3 trials
display_haveabreak_message = true;
console.log('Should I have a break? I have missed many trials: ' + trial_last3matches_misses);
return true;
} else {
display_haveabreak_message = false;
console.log('No need for a break! Only missed few trials: ' + trial_last3matches_misses);
return false;
}
} else {
console.log('trial number not yet 12. Current one: ' + trial_absolute_count);
return false;
}
},
};
//set up practice block
for (var i=0; i<practice_trial_info.length; i++) {
// add fixation to this trial
// set up the fixation, since this will be the same for all trials
var fixation = {
type: 'image-keyboard-response',
stimulus: fixation_image,
choices: jsPsych.NO_KEYS,
trial_duration: fixation_duration,
data: {trial_segment: 'fixation', condition: practice_trial_info[i].condition}
}
timeline.push(fixation);
// set up emotion image and add to this trial
var emotion = {
type: 'image-keyboard-response',
stimulus: practice_trial_info[i].emotion_image,
choices: jsPsych.NO_KEYS,
trial_duration: IAPS_duration,
data: {trial_segment: 'emotion', condition: practice_trial_info[i].condition}
}
timeline.push(emotion);
// set up stop signal trials
if (practice_trial_info[i].condition == "stop") {
// set up target arrow and add to this trial
var target_arrow = {
type: 'image-keyboard-response',
stimulus: practice_trial_info[i].arrow_image,
choices: ['c','n'],
response_ends_trial: false,
trial_duration: function() {
return delay;
},
data: {
trial_segment: 'target',
condition: practice_trial_info[i].condition
}
}
timeline.push(target_arrow);
// set up stop signal and add to this trial
var stop_signal = {
type: 'image-keyboard-response',
stimulus: stop_image,
choices: ['c','n'],
response_ends_trial: false,
trial_duration: stopStim_duration,
post_trial_gap: stopStim_post_trial_gap_duration,
data: {
block: 'practice',
trial_absolute: function() {
return trial_absolute_count;
},
trial_within: function() {
return practice_within_count;
},
trial_stop_number: function() {
return practice_stop_count;
},
emotion_type: practice_trial_info[i].emotion_type,
trial_segment: 'stop_signal',
condition: practice_trial_info[i].condition,
arrow_direction: practice_trial_info[i].arrow_direction,
arrow_key_correct: practice_trial_info[i].arrow_key_correct,
trial_response_correct: practice_trial_info[i].trial_response_correct,
SSD: function() {
return delay;
}
},
on_finish: function(data) {
// score response
trial_absolute_count += 1;
practice_stop_count += 1;
practice_within_count += 1;
var correct = true;
var inhibit = 1;
var last_trial_data = jsPsych.data.get().last(2).values()[0];
var trial_response = 'x';
var current_delay = 0;
// if unsuccesful inhibition, decrease SSD so that it is easier to stop
if (data.key_press !== null || last_trial_data.key_press !== null) {
correct = false;
inhibit = 0;
delay -= 25;
if (last_trial_data.key_press !== null) {
data.rt = last_trial_data.rt;
}
else if (data.key_press !== null) {
data.rt = data.rt + current_delay;
}
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "c" || jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(last_trial_data.key_press) == "c") {
trial_response = 'l';
}
else if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "n" || jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(last_trial_data.key_press) == "n") {
trial_response = 'r';
}
}
// if successful inhibition, increase SSD so that it is harder to stop
else {
delay += 25;
}
// add accuracy to the data for this trial
data.trial_response = trial_response;
data.successful_inhibit = inhibit;
data.correct = correct;
}
}
// add the no-go arrow trial (no-go trials only)
timeline.push(stop_signal);
// add the practice feedback (practice block only)
timeline.push(practice_correct_stop_conditional);
timeline.push(practice_wrong_stop_conditional);
} else {
// set up the go trial and add to timeline
var target_arrow = {
type: 'image-keyboard-response',
stimulus: practice_trial_info[i].arrow_image,
choices: ['c','n'],
response_ends_trial: true,
trial_duration: goStim_duration,
post_trial_gap: goStim_post_trial_gap_duration,
data: {
block: 'practice',
trial_absolute: function() {
return trial_absolute_count;
},
trial_within: function() {
return practice_within_count;
},
trial_go_number: function() {
return practice_go_count;
},
emotion_type: practice_trial_info[i].emotion_type,
trial_segment: 'target',
condition: practice_trial_info[i].condition,
arrow_direction: practice_trial_info[i].arrow_direction,
arrow_key_correct: practice_trial_info[i].arrow_key_correct,
trial_response_correct: practice_trial_info[i].trial_response_correct
},
on_finish: function(data) {
// score response
trial_absolute_count += 1;
practice_go_count += 1;
practice_within_count += 1;
var correct = false;
var trial_response = 'x';
// if we add the correct key response to the trial data, then we can use it to score the response
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == data.arrow_key_correct) {
correct = true;
}
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "c") {
trial_response = 'l';
}
else if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "n") {
trial_response = 'r';
}
// add accuracy to data for this trial
data.correct = correct;
data.trial_response = trial_response;
}
};
timeline.push(target_arrow);
// add the too slow conditional node (go trials only)
timeline.push(practice_correct_go_conditional);
timeline.push(practice_wrong_go_conditional);
timeline.push(too_slow_conditional);
}
}
// set up instructions post practice
var post_practice_instructions = {
type: 'instructions',
pages: ["<h1>💡<br>Nice!</h1><p>Now you probably have an idea how this works." +
"<p>From now on there will be no feedback on your performance.</p>" +
"<h2>Press space to continue</h2>",
"<h1>🔔<br>A quick reminder</h1>" +
"<p>Press the C-key when you see the left arrow. <br>Press the N-key when you see the right arrow.<br><b>Stop and don't press anything</b> if the up arrow appers. </p>" +
"<h2>Ready? Press space to start</h2>",
],
key_forward: 32, // code for space
show_clickable_nav: false
};
timeline.push(post_practice_instructions);
//set up block1
for (var i=0; i<block1_trial_info.length; i++) {
// add fixation to this trial
// set up the fixation, since this will be the same for all trials
var fixation = {
type: 'image-keyboard-response',
stimulus: fixation_image,
choices: jsPsych.NO_KEYS,
trial_duration: fixation_duration,
data: {trial_segment: 'fixation', condition: block1_trial_info[i].condition}
}
timeline.push(fixation);
// set up emotion image and add to this trial
var emotion = {
type: 'image-keyboard-response',
stimulus: block1_trial_info[i].emotion_image,
choices: jsPsych.NO_KEYS,
trial_duration: IAPS_duration,
data: {trial_segment: 'emotion', condition: block1_trial_info[i].condition}
}
timeline.push(emotion);
// set up stop signal trials
if (block1_trial_info[i].condition == "stop") {
// set up target arrow and add to this trial
var target_arrow = {
type: 'image-keyboard-response',
stimulus: block1_trial_info[i].arrow_image,
choices: ['c','n'],
response_ends_trial: false,
trial_duration: function() {
return delay;
},
data: {
trial_segment: 'target',
condition: block1_trial_info[i].condition
}
}
timeline.push(target_arrow);
// set up stop signal and add to this trial
var stop_signal = {
type: 'image-keyboard-response',
stimulus: stop_image,
choices: ['c','n'],
response_ends_trial: false,
trial_duration: stopStim_duration,
post_trial_gap: stopStim_post_trial_gap_duration,
data: {
block: 'block1',
trial_absolute: function() {
return trial_absolute_count;
},
trial_within: function() {
return block1_within_count;
},
trial_stop_number: function() {
return block1_stop_count;
},
emotion_type: block1_trial_info[i].emotion_type,
trial_segment: 'stop_signal',
condition: block1_trial_info[i].condition,
arrow_direction: block1_trial_info[i].arrow_direction,
arrow_key_correct: block1_trial_info[i].arrow_key_correct,
trial_response_correct: block1_trial_info[i].trial_response_correct,
SSD: function() {
return delay;
}
},
on_finish: function(data) {
// score response
trial_absolute_count += 1;
block1_stop_count += 1;
block1_within_count += 1;
var correct = true;
var inhibit = 1;
var last_trial_data = jsPsych.data.get().last(2).values()[0];
var trial_response = 'x';
var current_delay = 0;
// if unsuccesful inhibition, decrease SSD so that it is easier to stop
if (data.key_press !== null || last_trial_data.key_press !== null) {
correct = false;
inhibit = 0;
delay -= 25;
if (last_trial_data.key_press !== null) {
data.rt = last_trial_data.rt;
}
else if (data.key_press !== null) {
data.rt = data.rt + current_delay;
}
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "c" || jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(last_trial_data.key_press) == "c") {
trial_response = 'l';
}
else if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "n" || jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(last_trial_data.key_press) == "n") {
trial_response = 'r';
}
}
// if successful inhibition, increase SSD so that it is harder to stop
else {
delay += 25;
}
// add accuracy to the data for this trial
data.trial_response = trial_response;
data.successful_inhibit = inhibit;
data.correct = correct;
}
}
// add the no-go arrow trial (no-go trials only)
timeline.push(stop_signal);
} else {
// set up the go trial and add to timeline
var target_arrow = {
type: 'image-keyboard-response',
stimulus: block1_trial_info[i].arrow_image,
choices: ['c','n'],
response_ends_trial: true,
trial_duration: goStim_duration,
post_trial_gap: goStim_post_trial_gap_duration,
data: {
block: 'block1',
trial_absolute: function() {
return trial_absolute_count;
},
trial_within: function() {
return block1_within_count;
},
trial_go_number: function() {
return block1_go_count;
},
emotion_type: block1_trial_info[i].emotion_type,
trial_segment: 'target',
condition: block1_trial_info[i].condition,
arrow_direction: block1_trial_info[i].arrow_direction,
arrow_key_correct: block1_trial_info[i].arrow_key_correct,
trial_response_correct: block1_trial_info[i].trial_response_correct
},
on_finish: function(data) {
// score response
trial_absolute_count += 1;
block1_go_count += 1;
block1_within_count += 1;
var correct = false;
var trial_response = 'x';
// if we add the correct key response to the trial data, then we can use it to score the response
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == data.arrow_key_correct) {
correct = true;
}
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "c") {
trial_response = 'l';
}
else if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "n") {
trial_response = 'r';
}
// add accuracy to data for this trial
data.correct = correct;
data.trial_response = trial_response;
}
};
timeline.push(target_arrow);
timeline.push(display_haveabreak_message_conditional);
}
}
//set up instructions post block 1
var post_block1_instructions = {
type: 'instructions',
pages: ["<h2>Need a break?</h2><p>Have a good strech if feel like you need it.</p>" +
"<h2>Press space when you are ready to continue. </h2>"
],
key_forward: 32, // code for space
show_clickable_nav: false
};
timeline.push(post_block1_instructions);
//set up block 2
for (var i=0; i<block2_trial_info.length; i++) {
// add fixation to this trial
// set up the fixation, since this will be the same for all trials
var fixation = {
type: 'image-keyboard-response',
stimulus: fixation_image,
choices: jsPsych.NO_KEYS,
trial_duration: 500,
data: {trial_segment: 'fixation', condition: block2_trial_info[i].condition}
}
timeline.push(fixation);
// set up emotion image and add to this trial
var emotion = {
type: 'image-keyboard-response',
stimulus: block2_trial_info[i].emotion_image,
choices: jsPsych.NO_KEYS,
trial_duration: 1000,
data: {trial_segment: 'emotion', condition: block2_trial_info[i].condition}
}
timeline.push(emotion);
// set up stop signal trials
if (block2_trial_info[i].condition == "stop") {
// set up target arrow and add to this trial
var target_arrow = {
type: 'image-keyboard-response',
stimulus: block2_trial_info[i].arrow_image,
choices: ['c','n'],
response_ends_trial: false,
trial_duration: function() {
return delay;
},
data: {
trial_segment: 'target',
condition: block2_trial_info[i].condition
}
}
timeline.push(target_arrow);
// set up stop signal and add to this trial
var stop_signal = {
type: 'image-keyboard-response',
stimulus: stop_image,
choices: ['c','n'],
response_ends_trial: false,
trial_duration: 1000,
post_trial_gap: 1000,
data: {
block: 'block2',
trial_absolute: function() {
return trial_absolute_count;
},
trial_within: function() {
return block2_within_count;
},
trial_stop_number: function() {
return block2_stop_count;
},
emotion_type: block2_trial_info[i].emotion_type,
trial_segment: 'stop_signal',
condition: block2_trial_info[i].condition,
arrow_direction: block2_trial_info[i].arrow_direction,
arrow_key_correct: block2_trial_info[i].arrow_key_correct,
trial_response_correct: block2_trial_info[i].trial_response_correct,
SSD: function() {
return delay;
}
},
on_finish: function(data) {
// score response
trial_absolute_count += 1;
block2_stop_count += 1;
block2_within_count += 1;
var correct = true;
var inhibit = 1;
var last_trial_data = jsPsych.data.get().last(2).values()[0];
var trial_response = 'x';
var current_delay = 0;
// if unsuccesful inhibition, decrease SSD so that it is easier to stop
if (data.key_press !== null || last_trial_data.key_press !== null) {
correct = false;
inhibit = 0;
delay -= 25;
if (last_trial_data.key_press !== null) {
data.rt = last_trial_data.rt;
}
else if (data.key_press !== null) {
data.rt = data.rt + current_delay;
}
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "c" || jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(last_trial_data.key_press) == "c") {
trial_response = 'l';
}
else if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "n" || jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(last_trial_data.key_press) == "n") {
trial_response = 'r';
}
}
// if successful inhibition, increase SSD so that it is harder to stop
else {
delay += 25;
}
// add accuracy to the data for this trial
data.trial_response = trial_response;
data.successful_inhibit = inhibit;
data.correct = correct;
}
}
// add the no-go arrow trial (no-go trials only)
timeline.push(stop_signal);
} else {
// set up the go trial and add to timeline
var target_arrow = {
type: 'image-keyboard-response',
stimulus: block2_trial_info[i].arrow_image,
choices: ['c','n'],
response_ends_trial: true,
trial_duration: 1000,
post_trial_gap: 500,
data: {
block: 'block2',
trial_absolute: function() {
return trial_absolute_count;
},
trial_within: function() {
return block2_within_count;
},
trial_go_number: function() {
return block2_go_count;
},
emotion_type: block2_trial_info[i].emotion_type,
trial_segment: 'target',
condition: block2_trial_info[i].condition,
arrow_direction: block2_trial_info[i].arrow_direction,
arrow_key_correct: block2_trial_info[i].arrow_key_correct,
trial_response_correct: block2_trial_info[i].trial_response_correct
},
on_finish: function(data) {
// score response
trial_absolute_count += 1;
block2_go_count += 1;
block2_within_count += 1;
var correct = false;
var trial_response = 'x';
// if we add the correct key response to the trial data, then we can use it to score the response
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == data.arrow_key_correct) {
correct = true;
}
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "c") {
trial_response = 'l';
}
else if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "n") {
trial_response = 'r';
}
// add accuracy to data for this trial
data.correct = correct;
data.trial_response = trial_response;
}
};
timeline.push(target_arrow);
timeline.push(display_haveabreak_message_conditional);
// add the too slow conditional node (go trials only)
}
}
//set up instructions post block 2
var post_block2_instructions = {
type: 'instructions',
pages: ["<h2>Need a break?</h2><p>Have a good strech if feel like you need it.</p>" +
"<h2>Press space when you are ready to continue. </h2>"
],
key_forward: 32, // code for space
show_clickable_nav: false
};
timeline.push(post_block2_instructions);
//set up block 3
for (var i=0; i<block3_trial_info.length; i++) {
// add fixation to this trial
// set up the fixation, since this will be the same for all trials
var fixation = {
type: 'image-keyboard-response',
stimulus: fixation_image,
choices: jsPsych.NO_KEYS,
trial_duration: 500,
data: {trial_segment: 'fixation', condition: block3_trial_info[i].condition}
}
timeline.push(fixation);
// set up emotion image and add to this trial
var emotion = {
type: 'image-keyboard-response',
stimulus: block3_trial_info[i].emotion_image,
choices: jsPsych.NO_KEYS,
trial_duration: 1000,
data: {trial_segment: 'emotion', condition: block3_trial_info[i].condition}
}
timeline.push(emotion);
// set up stop signal trials
if (block3_trial_info[i].condition == "stop") {
// set up target arrow and add to this trial
var target_arrow = {
type: 'image-keyboard-response',
stimulus: block3_trial_info[i].arrow_image,
choices: ['c','n'],
response_ends_trial: false,
trial_duration: function() {
return delay;
},
data: {
trial_segment: 'target',
condition: block3_trial_info[i].condition
}
}
timeline.push(target_arrow);
// set up stop signal and add to this trial
var stop_signal = {
type: 'image-keyboard-response',
stimulus: stop_image,
choices: ['c','n'],
response_ends_trial: false,
trial_duration: 1000,
post_trial_gap: 1000,
data: {
block: 'block3',
trial_absolute: function() {
return trial_absolute_count;
},
trial_within: function() {
return block3_within_count;
},
trial_stop_number: function() {
return block3_stop_count;
},
emotion_type: block3_trial_info[i].emotion_type,
trial_segment: 'stop_signal',
condition: block3_trial_info[i].condition,
arrow_direction: block3_trial_info[i].arrow_direction,
arrow_key_correct: block3_trial_info[i].arrow_key_correct,
trial_response_correct: block3_trial_info[i].trial_response_correct,
SSD: function() {
return delay;
}
},
on_finish: function(data) {
// score response
trial_absolute_count += 1;
block3_stop_count += 1;
block3_within_count += 1;
var correct = true;
var inhibit = 1;
var last_trial_data = jsPsych.data.get().last(2).values()[0];
var trial_response = 'x';
var current_delay = 0;
// if unsuccesful inhibition, decrease SSD so that it is easier to stop
if (data.key_press !== null || last_trial_data.key_press !== null) {
correct = false;
inhibit = 0;
delay -= 25;
if (last_trial_data.key_press !== null) {
data.rt = last_trial_data.rt;
}
else if (data.key_press !== null) {
data.rt = data.rt + current_delay;
}
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "c" || jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(last_trial_data.key_press) == "c") {
trial_response = 'l';
}
else if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "n" || jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(last_trial_data.key_press) == "n") {
trial_response = 'r';
}
}
// if successful inhibition, increase SSD so that it is harder to stop
else {
delay += 25;
}
// add accuracy to the data for this trial
data.trial_response = trial_response;
data.successful_inhibit = inhibit;
data.correct = correct;
}
}
// add the no-go arrow trial (no-go trials only)
timeline.push(stop_signal);
} else {
// set up the go trial and add to timeline
var target_arrow = {
type: 'image-keyboard-response',
stimulus: block3_trial_info[i].arrow_image,
choices: ['c','n'],
response_ends_trial: true,
trial_duration: 1000,
post_trial_gap: 500,
data: {
block: 'block3',
trial_absolute: function() {
return trial_absolute_count;
},
trial_within: function() {
return block3_within_count;
},
trial_go_number: function() {
return block3_go_count;
},
emotion_type: block3_trial_info[i].emotion_type,
trial_segment: 'target',
condition: block3_trial_info[i].condition,
arrow_direction: block3_trial_info[i].arrow_direction,
arrow_key_correct: block3_trial_info[i].arrow_key_correct,
trial_response_correct: block3_trial_info[i].trial_response_correct
},
on_finish: function(data) {
// score response
trial_absolute_count += 1;
block3_go_count += 1;
block3_within_count += 1;
var correct = false;
var trial_response = 'x';
// if we add the correct key response to the trial data, then we can use it to score the response
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == data.arrow_key_correct) {
correct = true;
}
if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "c") {
trial_response = 'l';
}
else if (jsPsych.pluginAPI.convertKeyCodeToKeyCharacter(data.key_press) == "n") {
trial_response = 'r';
}
// add accuracy to data for this trial
data.correct = correct;
data.trial_response = trial_response;
}
};
timeline.push(target_arrow);
timeline.push(display_haveabreak_message_conditional);
}
}
// add end message
var end = {
type: 'html-keyboard-response',
stimulus: '<h1>🎊<br>Great!</h1>You're done with this task.<br>Thank you for your time.</p>',
trial_duration: 5000
};
jatos.onLoad(function() {
jsPsych.data.addProperties({
jatos_study_ID: jatos.studyId,
jatos_component_ID: jatos.componentId,
jatos_component_result_ID: jatos.componentResultId,
jatos_worker_ID: jatos.workerId,
jatos_study_result_ID: jatos.studyResultId,
});
jsPsych.init({
timeline: timeline,
show_progress_bar: true,
show_preload_progress_bar: true, //hide preload progress bar
on_finish: function() {
// jsPsych.data.displayData();
var result_json = jsPsych.data.get().json() + jsPsych.data.getInteractionData().json(); // This added on part after the + is to send browser interactions to JATOS in addition to trial data
jatos.submitResultData(result_json, jatos.startNextComponent);
}