How to generate different stimulus parameters on every trial repetition? #1702
-
Dear All, In my experiment, participants are presented with two Gabor patches in a trial. I have a few stimulus parameters such as the contrast of the patches, the correct key_press that are generated on_start of the display of the patches. I also have some crucial data such as the correct response on the trial and whether a participant missed a trial or not that gets start on_finish of the display of the patches. There are 8 conditions in my experiment and the stimulus parameters keep changing. Currently, I just repeat the code 8 times so that the different parameters are generated. I am looking for a way in which I can use a function once so that the patches are generated with different stimulus parameters.
Right now, I am just repeating this in the code. This makes the code way too long. Is there a way to not repeat it and by writing a function that will generate the patches with different stimulus parameters? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi Prashanti. Sorry for the delay getting back to you. function gabor(c, index1, reward, difference, contrast, contrast1) {
\\ ... (BTW you can see more examples of canvas drawing functions with additional parameters in the canvas-* example files, such as the jspsych-canvas-button-response.html file.) var gabor_trial = {
stimulus: function(c) {
// call the gabor function with the canvas context (c, passed in automatically from the plugin),
// and all of the other trial-specific parameters that affect the way that the stimulus is drawn
gabor(c, jsPsych.timelineVariable('index1'), jsPsych.timelineVariable('reward'), jsPsych.timelineVariable('difference'), jsPsych.timelineVariable('contrast'), jsPsych.timelineVariable('contrast1'));
},
on_finish: function(data){
// merge all timeline variables for this trial into the trial data
Object.assign(data, jsPsych.allTimelineVariables());
},
// other parameters ...
}; Note: the above should work if you're using jsPsych v6.3.1+. If you're using an earlier version, then you will need to add gabor(c, jsPsych.timelineVariable('index1', true), ... etc. ) And the data: {index1: jsPsych.timelineVariable('index1'), reward: jsPsych.timelineVariable('reward'), ... etc. } Finally, you can set up all your trials using timeline variables, so that the trial information in the timeline_variables array contains all of the parameters that can change across trials. Something like this: var trial_info = [
{index1: 1, reward: 2, difference: 3, contrast: 4, contrast1: 5, condition: 'condition_1'},
{index1: 6, reward: 7, difference: 8, contrast: 9, contrast1: 10, condition: 'condition_2'},
// ... etc.
] This means you only need to define a single gabor trial, which you can use for all of your different conditions. var gabor_procedure = {
timeline: [gabor_trial],
timeline_variables: trial_info
}; I hope that makes sense and works for you? Please let us know if I've misunderstood your problem or if you have any further questions. |
Beta Was this translation helpful? Give feedback.
Hi Prashanti. Sorry for the delay getting back to you.
What I would do here is add some parameters to the
gabor
function so that it is able to draw the stimuli for all of your conditions, depending on the values of these parameters. I don't fully understand what you're doing here, so I may be wrong, but I think the easiest way to do this is to pass it all of the parameters that you are currently setting in the trial'son_start
function, something like this:(BTW you can see more examples of canvas drawing functions with additional parameters in the canvas-* example files, such as the jspsych-canvas-button-respo…