Replies: 1 comment 2 replies
-
This is giving an error because the last line (where you use jsPsych.data.Get()) is executed immediately when you load your script. But at that point the survey trial has not been executed yet. Therefore, accessing data from the last trial will not work (because basically there is no last trial yet). Depending on where you need to have this information, I would create a variable fileId before you create your survey trial, i.e.:
You can then update this variable in the on_finish function
To convert a string to an integer you can use the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm trying to extract the value within on_finish function and use it for a file name.
Below is the code I tried
`var survey_trial = {
type: 'survey-text',
preamble: "Please fill out the information below",
questions: [
{prompt: "Participant ID", name: 'rawID'}
],
on_finish: function(data){
var responses = JSON.parse(data.responses);
var RawID = responses.rawID;
jsPsych.data.addProperties({rawID:RawID});
var fileId = RawID;
}
};
var fileIdd = jsPsych.data.get().last(1).values()[0].fileId;
`
The last line is giving me an error, and I could not figure out how to solve it. I was also wondering how I should change the variable "fileId" to numeric variable so that I could use it for choosing a stimuli list. Any help would be much appreciated!
Beta Was this translation helpful? Give feedback.
All reactions