I am currently having an issue figuring out where to fix my code for my custom loop. Here is a picture of my set up:
I have 8 sets of word lists that only have 4 trials. After the four trials finish, the participant should enter into either a “blank” screen or complete a round of random math equations. After the blank screen or math equations, they complete a recall task that should keep track of what they previously saw. I currently have custom code that is set up to call a datafile and read in the stimuli and reiterate through that. I’m not really sure where I’m having an issue.
This is the code on my Begin Experiment routine:
from random import shuffle
import random
import pandas
list_0 = ['A','B']
list_25 = ['I','J']
list_50 = ['Q','R']
list_75 = ['Y','Z']
list_task_0 = ['blank','math']
list_task_25 = ['math','blank']
list_task_50 = ['blank','math']
list_task_75 = ['math','blank']
shuffle(list_0)
shuffle(list_25)
shuffle(list_50)
shuffle(list_75)
shuffle(list_task_0)
shuffle(list_task_25)
shuffle(list_task_50)
shuffle(list_task_75)
# Pair each element from list_0 and list_25 with the corresponding task
pairsList_0 = [{'item': item, 'task': task} for item, task in zip(list_0, list_task_0)]
pairsList_25 = [{'item': item, 'task': task} for item, task in zip(list_25, list_task_25)]
pairsList_50 = [{'item': item, 'task': task} for item, task in zip(list_50, list_task_50)]
pairsList_75 = [{'item': item, 'task': task} for item, task in zip(list_75, list_task_75)]
# Combine the two lists
all_pairsList = pairsList_0 + pairsList_25 + pairsList_50 + pairsList_75
shuffle(all_pairsList)
trial_list = all_pairsList
##################################################
loop_counter = 0
# Get the current trial dictionary
current_trial = trial_list[loop_counter]
# Set the conditions file based on 'item'
item_file = f"{current_trial['item']}.xlsx"
task_file = f"{current_trial['task']}.xlsx"
retrieval_file = f"{current_trial['item']}_Retrieval.xlsx"
# Save information to be used in the next routine
thisExp.addData('current_trial_item', current_trial['item'])
thisExp.addData('current_trial_task', current_trial['task'])
In theory, this should be controlling the conditions that are shown so that the lists receive one math and one blank condition. NOTE: The last part of the code I have tried to get rid of multiple times, but then it errors out on me and says variables don’t exist. If I initialize the variables, they never get filled.
Here is the code on my WM_WP_L1 variable:
loop_counter = phase2.thisN
# Get the current trial dictionary
current_trial = trial_list[loop_counter]
# Set the conditions file based on 'item'
item_file = f"{current_trial['item']}.xlsx"
task_file = f"{current_trial['task']}.xlsx"
# Save information to be used in the next routine
thisExp.addData('current_trial_item', current_trial['item'])
thisExp.addData('current_trial_task', current_trial['task'])
print(trial_list[loop_counter])
Again, in theory, this is suppose to only set the list to the current loop counter. This is what iterates to the new list after 4 trials. The loop counter appears to work correctly and gives output that looks like this:
Now, the issue is, despite the correct item and task and loop_counter, it draws the first list of words twice. So, it gives me 8 total lists, with the first list being repeated twice.
I have no clue where the code is going wrong. Any insight?