OK, let’s break this down a bit.
First, the first block of code in your post looks generally good. All of that should go in the “Before Experiment” tab because it’s setting up stuff you will be referring to later.
For the image component you would need to put something like B1stim_1[0]
or some other way or referring to items within the list. The reason is that B1stim_1 is a list. If you run the code you put and then tell it to print B1stim_1, this is what you get:
['v5.png', 'v9.png', 'v8.png', 'v12.png', 'h10.png', 'h5.png', 'h11.png', 'h6.png']
The trick is that you need to reference each of these individually on every loop, and you want them (presumably) in a different order every time. That’s a little harder.
This is where it becomes important whether you are planning to only run this in the lab or also run it online. If you’re only planning to run it in the lab, one way forward is to actually create a conditions file in the “before experiment” code that you can just refer to normally in your loops. In other words, save three condition files, Block1.xlsx, Block2.xlsx, Block3.xlsx. It’s easier to do this if you make a dict like so:
import random
import pandas as pd
random.seed()
# Stimuli
vertical_stimuli = ["v1.png", "v2.png", "v3.png", "v4.png", "v5.png", "v6.png", "v7.png", "v8.png", "v9.png", "v10.png", "v11.png", "v12.png"]
horizontal_stimuli = ["h1.png", "h2.png", "h3.png", "h4.png", "h5.png", "h6.png", "h7.png", "h8.png", "h9.png", "h10.png", "h11.png", "h12.png"]
# Shuffle the stimuli
random.shuffle(vertical_stimuli)
random.shuffle(horizontal_stimuli)
# Pre-fill "go" and "nogo"
vgo={'img':[], 'gonogo':['go']*6}
vnogo={'img':[], 'gonogo':['nogo']*6}
hgo={'img':[], 'gonogo':['go']*6}
hnogo={'img':[], 'gonogo':['nogo']*6}
# Pair half of the vertical stimuli with "go"
for stimulus in vertical_stimuli[0:6]:
vgo['img'].append(stimulus)
# Pair the remaining half of the vertical stimuli with "nogo"
for stimulus in vertical_stimuli[6:12]:
vnogo['img'].append(stimulus)
# Pair half of the horizontal stimuli with "go"
for stimulus in horizontal_stimuli[0:6]:
hgo['img'].append(stimulus)
# Pair the remaining half of the horizontal stimuli with "nogo"
for stimulus in horizontal_stimuli[6:12]:
hnogo['img'].append(stimulus)
B1stim = {'img':[],'gonogo':[]}
for i in range(0,2):
B1stim['img'].append(vgo['img'][i])
B1stim['gonogo'].append(vgo['gonogo'][i])
B1stim['img'].append(vnogo['img'][i])
B1stim['gonogo'].append(vnogo['gonogo'][i])
B1stim['img'].append(hgo['img'][i])
B1stim['gonogo'].append(hgo['gonogo'][i])
B1stim['img'].append(hnogo['img'][i])
B1stim['gonogo'].append(hnogo['gonogo'][i])
B1stim = pd.DataFrame(data=B1stim)
B1stim.to_excel('Block1.xlsx')
# Etc. for B2 and B3stim.
This will save an excel file with two colums, ‘img’ and ‘gonogo’. It will be different on every run of the experiment.
Then in the builder you can make something like a nested loop that would look a bit like this (I didn’t fill in nreps correctly, but in your case I think it would be 3 and 3).
where Blocks.xlsx just has one column, ‘block’, with three entries, ‘Block1.xlsx’, ‘Block2.xlsx’, ‘Block3.xlsx’, and then the inner loop refers to that field to actually populate the trial.
Then you just need to refer to $img and $gonogo in the trial itself.
Now as for the response mapping, what you want to do is actually add an additional column to the dictionaries (and ultimately the block excel file) above that’s something like ‘t1_corrkey’ and is set by horizontal vs. vertical. For example:
vgo={'img':[], 'gonogo':['go']*6, 't1_corrkey':['a']*6}
# and etc. for vnogo and 's' for the horizontal ones
# and make sure to add it to B1stim etc. as well!
That will take care of t1_resp.corr automatically. For t2, rather than correct/incorrect, you just care if they hit the key at all, right? So you create a feedback trial, and you actually (counter-intuitively) want to put this in the “Begin routine” code of your feedback trial (which will remember the last responses from the previous trial)
t2_pass = False
if thisTrial['gonogo'] == 'go':
if 'k' in t2_resp.keys:
t2_pass = True
else:
if t2_resp.keys == None:
t2_pass = True
if t1_resp.corr and t2_pass:
msg = "Richtig"
elif ((t1_resp.keys == None) and (t2_resp.keys != None)): # if there is no answer for task1, but for task2 (never possible in nogo trial)
msg = "Falsche Reihenfolge"
elif ((t1_resp.keys == None) and (t2_resp.keys == None)): # if there is no answer at all
msg = "Zu langsam"
else:
msg = "Falsch"
Then your feedback trial text component just displays $msg. Something along these lines should work.