Select conditions file based on the participant's response

Hi, I am trying to create an N-back task in which participant will have to choose which versions would he rather do: 1-back or 2-back. Assuming that I can use conditionsFile as variable, I input this before the trial loop:

if key_resp.keys == 1:
    conditionsFile = 'one_back.xlsx'
    letter_col = 'black'
elif key_resp.keys == 2:
    conditionsFile = 'two_back.xlsx'
    letter_col = 'red'
elif key_resp.keys == 3:
    conditionsFile = 'three_back.xlsx'
    letter_col = 'purple'
elif key_resp.keys == 4:
    conditionsFile = 'four_back.xlsx'
    letter_col = 'brown'
elif key_resp.keys == 5:
    condition_file = 'five_back.xlsx'
    letter_col = 'green'
elif key_resp.keys == 6:
    conditionsFile = 'six_back.xlsx'
    letter_col = 'blue'

However, I get the following error:

ValueError: Conditions file not found: C:\Users\agleo\Documents\Programming_projects\TAMU\nback_experiment

is my assumption that i can use variable in conditions field incorrect? How would you advise to bypass it?

Hi,

If I understand your question correctly, this may help.

First, to make sure the code were added before the trial loop as you stated.

Second, click on the loop and set the conditions to be “$conditionsFile”, as it is a variable in your case, not a file name.

Hope this helps.

I think I did what you suggested, but to no avail. Maybe I am missing something? I attach my experiment general_trials.xlsx (8.6 KB) nback_v1.psyexp (13.8 KB) one_back.xlsx (9.0 KB) two_back.xlsx (9.0 KB)

Hi,

Maybe because different version we use of PsychoPy, I cannot see your code components here on my laptop, but I managed to see the original code, I guess I have found where the problem is, you can give it a go.

for the code you added, try to put numbers in quotation marks:


if key_resp.keys == '1':
    conditionsFile = 'one_back.xlsx'
    letter_col = 'black'
elif key_resp.keys == '2':
    conditionsFile = 'two_back.xlsx'
    letter_col = 'red'

etc. Because the keys should be recognised as a character instead of a numeric variable.

Thank you, that works perfectly!

Is there also a possibility to assign a condition file for half of my participant if a specific key is pressed. Let’s say: If a participant presses 1 and 1 matches with a picture A, I want to show picture A for half of my participants but also if they press 1 I want to show picture B for the other half?