using data from trial to set experiment variables

642 views
Skip to first unread message

anna...@gmail.com

unread,
Jul 21, 2015, 7:17:05 AM7/21/15
to jsp...@googlegroups.com
Hi,

I was wondering if it possible to set variables based on user input from a trial. I would like to start the experiment with adding a participant code in a text input field (this works with the survey plugin) and I would like to add this participant code to trials that come later in the experiment.

Is there a way to do this?

Thanks,

Anna

Josh de Leeuw

unread,
Jul 21, 2015, 1:16:26 PM7/21/15
to anna...@gmail.com, jsp...@googlegroups.com
Yes, you can do this. Something like:

var code_trial = {
  type: 'survey-text',
  questions: [['Enter participant code']],
  on_finish: function(data){
    var responses = JSON.parse(data.responses);
    var code = responses.Q0;
    jsPsych.data.addProperties({participantCode: code});
  }
}

The on_finish function will evaluate after the trial is over. It uses JSON.parse to read the responses variable, and responses.Q0 will be the response to the first question. Then you can use the jsPsych.data.addProperties function to add a property called participantCode to all trials (past, present, and future) with the value 'code'.

--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/780c0bb4-1657-4917-abb8-351536c9f2e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hassan.b...@gmail.com

unread,
Jul 22, 2018, 3:50:55 PM7/22/18
to jsPsych
I'm aware this is very old, but I'm wondering if it's possible to do something like this where javascript variables can be defined (e.g. var code in your example) that are then later used to define experiment trials. We are doing a 3-day experiment, and the stimuli encountered (defined in the main experiment js file) depend on which day it is, and which subject it is. Therefore we want a form before the instructions begin that the researchers can fill in, with the subject ID and the day of the experiment. When I try do this, the variable is said to not be defined. I think this might be a javascript issue, with the whole experiment being defined etc. before this page actually loads, so not being able to define variables that are used elsewhere using it. Is there any workaround?

Thanks

Hassan

Josh de Leeuw

unread,
Jul 22, 2018, 10:22:47 PM7/22/18
to hassan.b...@gmail.com, jsPsych
You're right about the cause of the problem. You might want to create the form for the experimenter to fill in outside of jsPsych, so that you can delay the build of all the experiment objects until after the variables are known. Alternatively, you could define the parameters for any trials that are dependent on this information using functions:


Reply all
Reply to author
Forward
0 new messages