Limiting consecutive same-key-correct trials and alternate pictures and words

Hi everyone!

I am in the process of programming an IAT in Builder, where my target concepts are presented as pictures and my attribute concepts are presented as words. For the combined-task trials I need to strictly alternate between pictures and words (so, targets and attributes) but the targets and attributes themselves should still be randomized. I’m pretty sure I would need a code component for that, but haven’t found an answer yet. Similarly, more than four consecutive same-key-correct answers should not be shown, to limit noise in data interpretation.
Does anyone have an answer to my question? Help would be greatly appreciated! :slight_smile:

Thank you in advance,
Natascha

So I did work out how to do it - only in Python though. The Auto translator to JS does not seem to work.
This is Begin Experiment (Python)
import random

test_data = data.importConditions(“images_training1/traning1.xlsx”)
trialQueue_1 =

chosen_counter = 0

current_key = “”
key_counter = 0

while chosen_counter < 24:
selected = random.choice(test_data)

if selected["correctAns_11"] == current_key and key_counter < 4:
    trialQueue_1.append(selected)
    test_data.remove(selected)
    
    key_counter = key_counter + 1
    chosen_counter = chosen_counter + 1
elif selected["correctAns_11"] != current_key:
    trialQueue_1.append(selected)
    test_data.remove(selected)
    
    key_counter = 1
    chosen_counter = chosen_counter + 1
    
    current_key = selected["correctAns_11"]

current_index_1 = 0

I already know that import does not work and have substituted it with the crib sheet suggestion. But everything else seemingly also does not work.
Begin Routine (Python):
current_trial = trialQueue_1[current_index_1]

Name_11 = current_trial[“Name_11”]
correctAns_11 = current_trial[“correctAns_11”]

current_index_1 = current_index_1 + 1

If somebody has any idea how to successfully translate this into JS that would be greatly appreciated!