| Reference | Downloads | Github

How do I access slider response in code component for future use?

Hi all,

I wanted to access the response (integer) to a slider component, store it in an array, and use the array in a later routine. I’ve tried a few methods in the JS code component, the console log either shows that the response is undefined or I would get an error.

Below is what I think I should do to access the slider response:

Begin Experiment:

trialCounter = 0;
rating = [];  // name of the array storing the slider response

Begin routine:

dat = NPOs.experimentHandler.psychoJS.experiment._trialsData;  // "NPOs" is the name of the loop
rating[trialCounter] = dat[trialCounter]['slider.response'];

End Routine:

trialCounter += 1;
psychoJS.experiment.addData('thisTrialN', trialCounter);

This would give me an error:
TypeError: Cannot read property ‘slider.response’ of undefined

I guess there’s an issue accessing the trial index here so I’m not able to retrieve the slider response.
I’m new to JS, and would appreciate any help in troubleshooting this.