I have two groups of stimuli, lets say S1-S5 and L1-L5.
I’d like to randomly pair the five stimuli in each group with these five durations [2, 2.5, 3, 3.5, 4].
I think I’m making progress, but get Pavlovia freezing. I just want to see if I am completely offbase in my approach.
shuffle = util.shuffle;
zip = function zip() {
var args = [].slice.call(arguments);
var shortest = args.length==0 ? [] : args.reduce(function(a,b){
return a.length<b.length ? a : b
});
return shortest.map(function(_,i){
return args.map(function(array){return array[i]})
});
}
#Create arrays for the two different sets of durations
SDurations = [2, 2.5, 3, 3.5, 4]
LDurations = [2, 2.5, 3, 3.5, 4]
#Create arrays for the two different sets of stimuli
SPrompts = ["S1", "S2", "S3", "S4", "S5"]
LPrompts = ["L1", "L2", "L3", "L4", "L5"]
#Shuffle Them
shuffle(SDurations)
shuffle(LDurations)
shuffle(SPrompts)
shuffle(LPrompts)
#Put the stim and durations together (now should be two columns of five rows each)
Small = list(zip(SPrompts, SDurations))
Large = list(zip(LPrompts, LDurations))
#Put the two types of stimuli together (now should be two columns of ten rows each)
TrialInfo = Small.concat(Large)
#Shuffle all of the trials
shuffle(TrialInfo)
Then to refer to stimuli or duration in the actual trial I believe I should be able to do this?
You don’t need list(). In fact, it’s not even a JS function
You should use $TrialInfo[trials.thisN][0] for the stimulus and $TrialInfo[trials.thisN][1] for the duration.
With this, I think it should work. What I usually do to debug my JS code, is using jsfiddle.net. There you can run your script and print its results to the console by using console.log(). This way, you don’t have to recompile a PsychoJS script any time you change something.