Ending Experiment after Mouseclick in Instruction Plugin

127 views
Skip to first unread message

jfis...@nd.edu

unread,
Sep 28, 2015, 1:41:31 PM9/28/15
to jsPsych
Hi,

I'm trying to do something very simple, but due to my naivety with javascript/programming it is proving somewhat difficult. 

Basically, I'm just trying to get the first block of my experiment to be a consent_block where the participant will click on an 'agree' button to proceed with the experiment or a 'disagree' button to end the experiment. 

To do this, I was thinking of making a few changes to the instructions plugin and have it send the 'disagree' information to the original HTML experiment file:
-  I changed the buttons within the instructions plugin from "previous" and "next" to "agree" and "disagree", as well as their IDs and functions. 
-  When the user clicks the 'disagree' button, it opens the 'disagree' function. I believe I should have the function return a certain value (e.g. var noagree = true) to the original HTML to let it know that the 'disagree' button was clicked. 
-  From there, I think I should end the consent_block in the original HTML experiment with an if function similar to what is found in the end-experiment.html example provided in the jsPsych download folder. 
- In that example, the code is as follows:
on_finish: function(data){
  if(data.key_press == 78){
    jsPsych.endExperiment();
  }
}  
- Unfortunately, I still don't have a decent-enough grasp of things to know how to properly have the information that the disagree button was clicked sent to the HTML experiment to signal an end to the experiment. 

Any tips would be greatly appreciated. Cheers.   
 
 

Josh de Leeuw

unread,
Oct 2, 2015, 10:26:52 AM10/2/15
to jfis...@nd.edu, jsPsych
The instructions plugin isn't quite set up to handle this, but there is another plugin that would work. It's not officially released yet, but it will be part of the next release and you can use it now. It's called button-response. 


Here's some code that should work for what you are trying to do:

var consent_trial = {
  type: 'button-response',
  stimuli: ['<p>Do you agree to participate in the experiment?</p>'],
  choices: ['Agree','Disagree'],
  on_finish: function(data){
    if(data.button_pressed == 1){
      jsPsych.endExperiment();
    }
  }
}

--
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/b8a07dfb-7375-4100-b508-cffcfc381f27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jfis...@nd.edu

unread,
Oct 2, 2015, 11:51:18 AM10/2/15
to jsPsych, jfis...@nd.edu
Awesome. It's working great. Thanks you! 
One other quick question if I may: Is there an easy way to enlarge the buttons in the plugin and center them on the screen?
Cheers,

Josh de Leeuw

unread,
Oct 2, 2015, 11:55:09 AM10/2/15
to jfis...@nd.edu, jsPsych
The to-be-released css file makes the buttons a bit prettier:

You can also edit the jspsych-btn class as you see fit.

jfis...@nd.edu

unread,
Oct 2, 2015, 11:58:16 AM10/2/15
to jsPsych, jfis...@nd.edu
Great. As always, I really appreciate your help. 
Reply all
Reply to author
Forward
0 new messages