jspsych-problem: Visual Analogue Scale - Showing pictures which are defined in a different script #3025
-
Hello everyone, I'm totally new in jspsych so I could really use some help with my programming-problem: Currently I defined a trial with an Analogue-Scale plugin. Within that trial I defined that 2 pictures should be seen by the participants in random order. Their task is to rate how similar both pictures are. Pretty straight forward so far. If this was the end of my problem the code would look like this in a classic way: //Preload Pictures//
var all_images = ['img/blue.png', 'img/orange.png', 'img/Kinski.jpg'
, 'img/Cola.jpg', 'img/santa.jpg', 'img/anger.jpg'];
//Defined Trial//
var trial_option_2 = {
type: jsPsychHtmlSliderResponse,
stimulus: function() {
var rand_images = jsPsych.randomization.sampleWithoutReplacement(all_images,2);
return `<div style="width:1000px;">
<p>How similar are the pictures?</p>
<div style="width:500; float: left;">
<img src="` + rand_images[0] + `" />
</div>
<div style="width:500; float: right;">
<img src="` + rand_images[1] + `" />
</div>
</div>`;
},
require_movement: true,
labels: ['not similar', 'quite similar', 'very similar']
};
//Timeline Push//
var test = {
timeline: [trial_option_2],
repetitions: 11 };
timeline.push(test); But of course it is more complicated. In this experiment there is no picture pool like above (var all images) The participants should receive individual trials/ pictures based on their predefined subject-ID which they have to insert at the beginning of the experiment. This code gets compared to all codes within an separate/ own .js file (inputFile.js) which contains all blocks and trials (for each code). The function to make this possible is: // preload//
//parameters//
var run_count = 1;
var block_count = 1;
var trial_count_encoding = 0;
var correct_response_count = 0;
var missed_response_count = 0;
//function//
// create array of images
var encoding_trial_pic = [function () {
// get the subject ID that was entered from the jsPsych.data object
var subject_ID = jsPsych.data.get().last(1).values()[0]['subject'];
// access the sub-dictionary containing the input data for this subject ID from inputFile.js
var my_stimuli = test[subject_ID];
// access the encoding block (first encoding block is indexed with 1 and all encoding blocks have odd indices)
var encoding_trials = my_stimuli[block_count];
// access the current trial; the trial counter variable serves as index for current trial
var this_trial = encoding_trials[trial_count_encoding];
// access the image path
var this_stimulus = this_trial['picture'];
// return the image path
return this_stimulus
}]; When I put this function inside the trial_option_2 trial, it looks like this: //Defined Trial//
var trial_option_2 = {
type: jsPsychHtmlSliderResponse,
stimulus: function() {
// get the subject ID that was entered from the jsPsych.data object
var subject_ID = jsPsych.data.get().last(1).values()[0]['subject'];
// access the sub-dictionary containing the input data for this subject ID from inputFileTempMemRandNew.js
var my_stimuli = test[subject_ID];
// access the encoding block (first encoding block is indexed with 1 and all encoding blocks have odd indices)
var encoding_trials = my_stimuli[block_count];
// access the current trial; the trial counter variable serves as index for current trial
var this_trial = encoding_trials[trial_count_encoding];
// access the image path
var this_stimulus = this_trial['picture'];
// access the current trial; the trial counter variable serves as index for current trial
var this_trial_x = encoding_trials[trial_count_encoding+1];
// access the image path
var this_stimulus_x = this_trial_x['picture'];
var encoding_trial_pic_X = [this_stimulus, this_stimulus_x,2];
return `<div style="width:1000px;">
<p>How similar are the pictures?</p>
<div style="width:500; float: left;">
<img src="` + encoding_trial_pic_X[0] + `" />
</div>
<div style="width:500; float: right;">
<img src="` + encoding_trial_pic_X[1] + `" />
</div>
</div>`;
},
require_movement: true,
labels: ['not similar', 'quite similar', 'very similar']
};
//Timeline Push//
var test = {
timeline: [trial_option_2],
repetitions: 11 };
timeline.push(test); Unfortunately it is not working right now. I don't know whether the defined function is wrong within the trial or not. Help would be absolutely appreciated! :) If you need additional information, feel free to ask. Best regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Conceptually, this seems right. I'm guessing the error is just a bug somewhere in the code. Have you tried using the debugging tools in your browser to step through the function? |
Beta Was this translation helpful? Give feedback.
-
Hello again, since my project is still running, several questions remain. I hope it is okay to further use this discussion-section. :) var test = {
"5370015366": {
"1": [
{
"positionInOrder": 1,
"picture": "teddy_bear_01b.jpg",
"category": "24_toy",
"categoryIndex": 0,
"congruence": 2,
"object": "1636_teddy_bear",
"wait_add_TR": false
},
{
"positionInOrder": 2,
"picture": "marble_06s.jpg",
"category": "24_toy",
"categoryIndex": 0,
"congruence": 1,
"object": "973_marble",
"wait_add_TR": false
},
{
"positionInOrder": 3,
"picture": "noisemaker_01b.jpg",
"category": "24_toy",
"categoryIndex": 0,
"congruence": 0,
"object": "1061_noisemaker",
"wait_add_TR": false
},
{
"positionInOrder": 4,
"picture": "ink_07s.jpg",
"category": "19_officeSupply",
"categoryIndex": 1,
"congruence": 4,
"object": "830_ink",
"wait_add_TR": false
},
{
"positionInOrder": 5,
"picture": "cart_10s.jpg",
"category": "26_vehicle",
"categoryIndex": 2,
"congruence": 8,
"object": "277_cart",
"wait_add_TR": true
},
{
"positionInOrder": 6,
"picture": "folder_09s.jpg",
"category": "19_officeSupply",
"categoryIndex": 1,
"congruence": 2,
"object": "626_folder",
"wait_add_TR": true
}
], Here are some information to understand the essential defined components:
I need a method at the beginning of each run (for all individual subjects and their entered ID's) which selects all pictures from all Blocks/ Trials (280 in total for each subject) out of inputFile.js and compromises them in one array. //Preload Pictures **via a certain function from inputFile.js**//
var all_images = [????????];
//Defined Trial//
var trial_option_2 = {
type: jsPsychHtmlSliderResponse,
stimulus: function() {
var rand_images = jsPsych.randomization.sampleWithoutReplacement(all_images,2);
return `<div style="width:1000px;">
<p>How similar are the pictures?</p>
<div style="width:500; float: left;">
<img src="` + rand_images[0] + `" />
</div>
<div style="width:500; float: right;">
<img src="` + rand_images[1] + `" />
</div>
</div>`;
},
require_movement: true,
labels: ['not similar', 'quite similar', 'very similar']
};
//Timeline Push//
var test = {
timeline: [trial_option_2],
repetitions: 40 };
timeline.push(test); Thank you again for your help and I will also look for additional answers myself in the web. :) Have a great day! |
Beta Was this translation helpful? Give feedback.
Hi Jodeleeuw,
you gave me the essential cue for the problem! <3
the following part of the code:
var my_stimuli = test[subject_ID];
interferred with the variable:
var test = {
timeline: [trial_option_2],
repetitions: 11 };
timeline.push(test);
Therefore the program did not know which "test" I meant. I changed the name of 'var test' to 'var test_1' and now it works.
Should I close this discussion now or can I leave it open for further question in the near future?
Thanks alot!
OberSchmetteBennett