psychopy.org | Reference | Downloads | Github

Array of objects as the condition file

Hi all,

I am trying to create unique pairs of stimuli for each participant. I created an array of objects as an example which basically is a unique pair of two elements from two different array.


const stimuli = [];

let Middle= [
  "mips","punes","pinds","renes","blans","heets","mouts","papes",
   "gruts","hoons","awops","snains","chails", "spaves", "bunges","goples",
   "dralys","dralis","burtes","curges","queels","squamps","striifs",
   "jundors","glukers","vennars","ganches","teartes","punties","firters",
   "sothods","veemers"
   ]

shuffle(Middle);

let Cat = [
  ["cars","Volvos","BMWs"], ["birds","parrots","sparrow"] , ["tools","hammers","saws"] , 
  ["criminals","robbers","murderers"],["boats","canoes","kayaks"], 
  ["reptiles","lizards","crocodiles"], ["trees","eucalyptus","willows"],
  ["drinks","beers","whiskeys"],["insects","bees","beetles"], 
  ["vegetables","cabbages","carrots"],["fruits","bananas","peaches"], 
  ["dogs","labradors","spaniel"], ["furniture","desks","sofas"],
  ["weapons","swords","guns"], ["currencies","dollars","euros"],
  ["fish","salmons","trout"]
  ];

shuffle(Cat);



// An example of one item
stimuli.push ({
  prem1: `All ${Cat[0][0]} are ${Middle[0]}`,
  prem2: `No ${Middle[0]} are ${Cat[1][1]}`,
  conc: `No ${Cat[0][0]} are ${Cat[1][1]}`
})

Now, my question is how to use this array as my condition file? I would appreciate any comments.

Hi @Omidrezaa, its easily done. Add this code to a “Begin Experiment” tab. Then, you need to remove the const from the stimuli declaration. Finally, add the stimuli variable as code to the loop e.g., $stimuli, in place of the filename.

1 Like