How to access response, which is collected as data by jspsych-html-slider-response #2135
-
Hello, I was looking into jspsych-html-slider-response, and it looks like this plugin collects the numeric value of the slider (response). This is silly, but I have been struggling with figuring out how to access response. I have been checking whether I can correctly access the numeric value on the slider the user selected by displaying it on my console. For some reason, this is the output: I was assuming that response is the first element given by getLastTrialData, but I am pretty sure that my assumption is wrong? I actually was looking into jsPsych.data.getLastTrialData, and it looks like it returns a DataCollection (which I think is different from an array)? Any help is much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi @rmtham, based on the code block you posted, it looks like you're trying to access the trial data in the main level of the experiment script. All of the code that sets up your experiment timeline etc. will run when the page first loads, which means that at that point, there's no data (because the experiment hasn't started yet). So if you want to access the data during the experiment, then that code will need to go inside a function that runs at a particular point during the experiment. Typically this is done inside event-related callback functions, which are functions that you create that will run after certain events take place during the experiment. In your case, if you want to check the response to var trial1 = {
type: 'html-slider-response',
// other parameters...
};
timeline.push(trial1);
var trial2 = {
type: 'html-keyboard-response',
stimulus: 'This is the next trial',
on_start: function() {
// when trial2 starts, check the data from the last trial
var last_trial_data = jsPsych.data.getLastTrialData().values()[0];
console.log('last trial data: ', last_trial_data);
}
};
timeline.push(trial2); You could also check the response to var trial1 = {
type: 'html-slider-response',
// other parameters...
on_finish: function(data) {
// when this trial ends, check the data
console.log('trial data: ', data);
console.log('response: ', data.response);
}
}; Do either of those solutions work for you? BTW you're absolutely right that the |
Beta Was this translation helpful? Give feedback.
-
Hi Becky, Thank you very much for the information! That makes a lot of sense, since I noticed that the information on the main level is always printed first, then the information within the trials. I was trying to access the trial data on the main level because I am trying to keep track of whether a subject correctly guesses 5 token values consecutively. If not, the subject will be asked what the values of the tokens are until they correctly guess all of the 5 token values one after another. One approach I thought that could work is creating a global variable to keep track of how many token values the subject correctly guesses after one round, then resetting this global variable to 0 once a round is finished. The global variable would be updated within the I am not sure how to implement this, I am thinking of looking into the jsPsych documentation a little bit more. If I still run into trouble, may I post on this discussion thread or would it be better if I create a new one? |
Beta Was this translation helpful? Give feedback.
Hi @rmtham, based on the code block you posted, it looks like you're trying to access the trial data in the main level of the experiment script. All of the code that sets up your experiment timeline etc. will run when the page first loads, which means that at that point, there's no data (because the experiment hasn't started yet). So if you want to access the data during the experiment, then that code will need to go inside a function that runs at a particular point during the experiment. Typically this is done inside event-related callback functions, which are functions that you create that will run after certain events take place during the experiment.
In your case, if you want to check…