returning a .js file to timeline_variables through a function #2256
-
Hi, I am trying to program an experiment where a participant sees an image (a board of words) and some words related to that image and makes some type of rating on it (image below). Each participant sees 20 different images, and each image has 12 different ratings that can be made. I want to randomize the order of the 20 images for each participant, as well as the order of the 12 ratings within each image, without having to declare a separate variable for each image. Critically, ratings for the same image should all happen together but the order of the images themselves should be randomized. I am trying to write code that will allow me to use the same javascript variable but change the image and the words based on a .json file which contains the path to that image and the specific words to be displayed. However, I am running into a couple issues:
I made sure that I loaded the .js files at the top of the code, and also if I directly pass Here is a snippet of my code, any input would be appreciated! var board = {
type: jsPsychImageSliderResponse,
stimulus: jsPsych.timelineVariable('boardname'),
stimulus_height: 400,
stimulus_width: 700,
prompt: jsPsych.timelineVariable('p1_final'),
prompt_above_slider: jsPsych.timelineVariable('p2_final'),
labels: ['1 (not likely at all)', '2', '3', '4', '5 (highly likely)'],
min: 1,
max : 5,
slider_start: 3,
data: jsPsych.timelineVariable('data')
};
// get a random order of boards for this subject
var myArray = [11,12, 13]; // this array is actually of length 20, using only 3 items for now
var shuffledBoard = jsPsych.randomization.sampleWithoutReplacement(myArray, 3);
console.log('order of boards is:', +shuffledBoard) // not working, returning NaN
// run a loop for this random order of boards
// purpose of loop is to get different stimuli depending on which board it is
// i want to use a function that returns a specific variable corresponding to a .js file of stimuli here
// and randomize the order of items within that board
for( var i = 0; i < myArray.length; i++){
console.log('value of i='+i);
console.log('value of number='+myArray[i]);
var board_proc = {
timeline: [board],
timeline_variables: function(){
return get_stimuli_list(myArray[i])
},
randomize_order: true
}
timeline.push(board_proc)
console.log('value of timeline='+timeline);
}
function get_stimuli_list(number){
console.log('get_stimuli_list has been called')
// takes in an integer from 1 through 20 and returns the correct stimuli file path
if (number == 11){
console.log('value of number='+number);
return stimuli_1_1
}
else {
console.log('value of number='+number);
return stimuli_1_2
}
} For more clarity, here is the structure of the var stimuli_1_1 = [
{
"wordpair": "exam - algebra",
"accuracy": "good",
"popularity": "high",
"value": "math",
"trial_type": "game",
"word1": "EXAM",
"word2": "ALGEBRA",
"Board": 1,
"Experiment": 1,
"boardnumber": 1.1,
"path": "boardimages/",
"boardname": "boardimages/1.1.png",
"p1.1": "<p>The targets are",
"p1.2": "and",
"p1.3": "</p>",
"p1_final": "<p>The targets are EXAM and ALGEBRA</p>",
"p2.1": "<p>Rate how likely you are to choose the clue",
"p2.2": "for the targets based on the board below </p>",
"p2_final": "<p>Rate how likely you are to choose the clue MATH for the targets based on the board below </p>"
}] |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @abhilasha-kumar ! Currently Does for( var i = 0; i < myArray.length; i++){
console.log('value of i='+i);
console.log('value of number='+myArray[i]);
var board_proc = {
timeline: [board],
timeline_variables: get_stimuli_list(myArray[i]),
randomize_order: true
}
} The only difference is that now |
Beta Was this translation helpful? Give feedback.
Hi @abhilasha-kumar !
Currently
timeline_variables
doesn't support using a function. It's something we'd like to add in the future.Does
get_stimuli_list()
change its value throughout the experiment? If the return value of this function is the same throughout the experiment, then I think you can omit the wrapper function like this:The only difference is that now
get_stimuli_list
will run at the start of the exp…