Linking responses of 2 different trial

Windows 10
PsychoPy 3

I’m a student and working for my thesis. I’ve been trying to create an Emotional Stroop with Error detection key. So, the way that the experiment is: starts by displaying facials with correct and incorrect emotion names, you can respond them with ‘a’ and ‘l’. If the emotion matches with the facial, the correct answer is ‘a’ and if not ‘l’.
In the loop, the other trial is an error detection trial. The key for the error detection is ‘space’ and it has to turn ‘1’ in the output if participant’s response is not correct and participant pressed ‘space’ for it. So if i make it thru coding language;
if resp_emstrp.corr is 1 and participant pressed ‘space’, the output should be ‘0’ in resp_errdtc_emstrp.corr
if resp_emstrp.corr is ‘0’ and participant pressed ‘space’, the output should be ‘1’ in resp_errdtc_emstrp.corr

so i’ve written a code:

if resp_emstrp.corr==0 and resp_errdtc_emstrp.keys=='space':
elif resp_emstrp.corr==1 and resp_errdtc_emstrp.keys=='space':
thisExp.addData("erdtcstrp", erdtcstrp)

files of the experiment:

Sorry for my bad english level.

Hello, you’ve described your task but please also tell us what the actual problem is.

i want resp_errdtc_emstrp.corr to be ‘1’ when resp_emstrp.corr is ‘0’ and when resp_emstrp.corr is ‘1’, resp_errdtc_emstrp.corr ‘0’. Error detection key is ‘space’. So when space is pressed by participant, i’ll know that participant has realized the incorrect answer of himself/herself. They’re in different trials but same loop. my code doesnt work when i try to create such dependecy.

You can use this code to save a variable named erdtcstrp in your csv file:

if resp_emstrp.corr==0 and resp_errdtc_emstrp.keys=='space':
    erdtcstrp =1
elif resp_emstrp.corr==1 and resp_errdtc_emstrp.keys=='space':
    erdtcstrp =0
thisExp.addData("erdtcstrp", erdtcstrp)

So, you do not need .cor part of the if statement. Moreover, it seems that you are assigning a varialble in your if statement, so you should use =, instead of ==.

sorry for the late reply, i had some health issues. the code didnt work. Output still gives 0 even if ‘space’ is pressed.
What i dont understand is how the code that written is not effecting both trials in the same loop.

No problem.

Then, you need to explain what you want more clearly. I just made some correction in your code and still do not know what do you want. Moreover, it is good to have some screenshots of your routines and csv file.

i hope it’s clear. sorry for the late reply again. and thank you for your time.

Ok, then let’s make it as easy as possible. First we define a variable to save the correct and incorrect response in the first routine. Then we use that variable in the later routine.

So, in the first routine, put this chunk in the code component:

## In the Begin Routine Tab:
emotion_accuracy = 'nothing'

## In the End RoutineTab:
# save correct and incorrect responses as a variable
if resp_emstrp.keys == 'a' and my_corr_ans_column == 'a': #change the name of column to the column that you use for corrAns
    emotion_accuracy = 'correct'
elif resp_emstrp.keys == 'i' and my_corr_ans_column == 'i': 
    emotion_accuracy = 'correct'
    emotion_accuracy = 'incorrect'

#And save the data
thisExp.addData ("emotion_accuracy", emotion_accuracy)

Now in the second routine, insert this code in a code component:

# Begin Routine
erdtcstrp = 99

# and in the end routine
if resp_errdct_emstrp.keys == 'space' and emotion_accuracy == 'incorrect':
    erdtcstrp= 1
if resp_errdct_emstrp.keys == 'space' and emotion_accuracy == 'correct':
   erdtcstrp= 0

#And save the data
thisExp.addData ("erdtcstrp", erdtcstrp)
1 Like

thank you for your reply, i understand the logic of it but there is another problem now.

erdtcstrp gives always 99, i dont know how to make it a variable.

I guess that the problem is with the first chunk of code. Could you please send a screenshot of your condition file with the column names as clear as possible? meanwhile, did you change my_corr_ans_column name to the name of your corrAns column? And finally, change erdtcstrp = 99 to erdtcstrp = '' to see if something happens.

PS. check the name of variables and make the code compatible to your variable names. In the datafile, it seems that the name of keyboard component in the detection routine is sth else.

1 Like

i had changed the variable names for my condition files as you say but i had the problem that i said. so it gives 99. Now i’ve tried erdtcstrp='', now it gives blank cell instead of 99 lol.

im sending you now my previous excel file. i’ve created these columns because i thought the conditions work as rows. So one row follows the other conditions but i couldnt have got the logic.

After applying the code you’ve sent, i’ve chanced the excel file like this.

I’m sending the properties of the keyboard components

Ok. first, the program read each rows of your condition row by row. So, your first condition file seems fine.

Second, I guess you do not need to set the corrAns in the keyboard component. I deleted those and it worked for me. I think it messes up with the name of variable that we created.

I build a sample of your experiment and it was working fine. You can find it attached. Let me know if you had any problems.

untitled.psyexp (13.2 KB) conditions.xlsx (8.3 KB)

1 Like

Yeah, it worked in my exp file. i cant thank you enough for your time and work :slight_smile:
So, i’ve changed the choice of ‘set every repeat’ to ‘constant’, and uncheck the box called ‘store corrrect’, then it all worked well. you taught me a lot bud.

1 Like

Happy to help.

Just test the program several times to make sure that it works the way that you want.

Good luck with your experiment.

1 Like