Continuing the discussion from Randomizing File Choice Across Two Blocks:
First off, I am a total newbie with JS (and also quite new with python/PsychoPy as well!), so I apologize if I am missing anything obvious, or if a similar solution has been posted elsewhere (although I haven’t been able to find one yet).
I have been trying to get an experiment to work online (from Builder) using the code provided by @Michael to have balanced presentation of stimulus types. Basically, I have three stimuli types (words, nonwords, and pseudowords) and two presentation blocks, where I need to have an equal presentation of each stimuli type in each block. I have been able to get the linked code to work perfectly for my experiment within PsychoPy, but translating to JS hasn’t been going so smoothly and I can’t get it to work online.
So far this is what I have for my code. I have a codeJS routine in a Begin Experiment tab before everything else to define shuffle=util.shuffle, and have tried to replace what I can with suggestions from @wakecarter’s crib sheet, but everything else I’m a bit lost on (and not sure if my replacements even make sense).
This code is in a routine before the start of the experiment, in a Begin Experiment tab:
PLDTwords = new TrialHandler({
psychoJS: psychoJS,
nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
extraInfo: expInfo, originPath: undefined,
trialList: 'PLDT_test_wd.csv',
seed: undefined, name: 'PLDTwords'});
PLDTnonwords = new TrialHandler({
psychoJS: psychoJS,
nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
extraInfo: expInfo, originPath: undefined,
trialList: 'PLDT_test_nw.csv',
seed: undefined, name: 'PLDTnonwords'});
PLDTpseudo = new TrialHandler({
psychoJS: psychoJS,
nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
extraInfo: expInfo, originPath: undefined,
trialList: 'PLDT_test_ph.csv',
seed: undefined, name: 'PLDTpseudo'});
//randomize words across trials and blocks:
shuffle(PLDTwords);
shuffle(PLDTnonwords);
shuffle(PLDTpseudo);
A1_words = [];
A1_words.push(PLDTwords[0:5],PLDTnonwords[0:7],PLDTpseudo[0:3]);
shuffle(A1_words);
B1_words = [];
B1_words.push(PLDTwords[5:10],PLDTnonwords[7:14],PLDTpseudo[3:6]);
shuffle(B1_words);
Then for the actual trials in my loop (here showing for the first block only as an example), I have this to call on each stimulus and record information in the data file:
trial_details = A1_words.shift();
current_PLDT_stim = trial_details(['stimText']);
current_PLDT_type = trial_details(['lex']);
current_PLDT_ans = trial_details(['correctAns']);
//record in data file
PLDT_A_loop.addData('stimText', current_PLDT_stim);
PLDT_A_loop.addData('lex', current_PLDT_type);
PLDT_A_loop.addData('correctAns', current_PLDT_ans);
Is it possible to do this with JS?
Thank you!
Kelsey