I was wondering if anyone had recommendations for how to impose a time limit on viewing instructions? In my task I'd like to make sure people don't spend too much time just sitting on the instructions pages between each block.
Is this answer still the best way to do this? https://groups.google.com/forum/#!topic/jspsych/r4yKaqPQkrk
It's a bit tricky to implement given my current timeline structure -- I'd like to try something else if possible. Are there any other suggestions for simpler methods?
Thanks!
--
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/54d07148-c936-4867-b08d-5ac43a2cad13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I'm having an issue with this change -- for some reason I keep getting a 'no plugin loaded for trials of type "html-keyboard-response"' error. I'm using the most recent Jspsych version from the github, and the plugin is definitely in my folder. Other plugins don't seem to be posing a problem and load just fine. Any ideas what might be the issue for this specifically?
Nevermind! It looks like one of my modifications to jspsych had screwed this up.
OK, so I've figured out my initial problems -- I'm using the version of jsPsych on the website, not on the github, so I don't have html-keyboard-response by default, and it's a different plugin format then my current ones, so it looks like it won't work just by dropping it in. So, I've tried creating a new plugin which modifies instructions to add a time limit argument. Right now, it works to stop instructions after a set amount of time, but if someone inputs a keystroke to advance the instructions before the time limit is up, then it introduces all sorts of errors -- my future categorize trials start displaying too many stimuli, being skipped too quickly, or not loading at all. I think it has something to do with me not setting up the timer correctly, but I'm not sure what I should do differently.
So, two questions:
1 - Should I just upgrade to the github version? If so, what do I need to do in order to do this beyond just replacing the files? I've tried just adding it to my static folder and redirecting all the script links to the new plugins, but that hasn't worked.
2 - If not, how should I fix the code below? I copied the whole plugin, but the pieces of interest are:
A - I added a new variable for the time limit
B - I added a timer which calls endTrial() if timeout happens
C - In the end trial by button press I tried to change the time limit variable to turn off the timeout.
TY for any help!
/* jspsych-text.js
* Josh de Leeuw
*
* This plugin displays text (including HTML formatted strings) during the experiment.
* Use it to show instructions, provide performance feedback, etc...
*
* documentation: docs.jspsych.org
*
*
*/
jsPsych.plugins.instructions = (function() {
var plugin = {};
plugin.trial = function(display_element, trial) {
trial.key_forward = trial.key_forward || 'rightarrow';
trial.key_backward = trial.key_backward || 'leftarrow';
trial.allow_backward = (typeof trial.allow_backward === 'undefined') ? true : trial.allow_backward;
trial.allow_keys = (typeof trial.allow_keys === 'undefined') ? true : trial.allow_keys;
trial.show_clickable_nav = (typeof trial.show_clickable_nav === 'undefined') ? false : trial.show_clickable_nav;
//EDITED
trial.time_limit = trial.time_limit || -1; // default is no max response time -- this was custom added!
// if any trial variables are functions
// this evaluates the function and replaces
// it with the output of the function
trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial);
var setTimeoutHandlers = [];
var current_page = 0;
var view_history = [];
var start_time = (new Date()).getTime();
var last_page_update_time = start_time;
//EDITED
if (trial.time_limit !== -1){
setTimeout(function() {
endTrial();
}, trial.time_limit);
}
function show_current_page() {
display_element.html(trial.pages[current_page]);
if (trial.show_clickable_nav) {
var nav_html = "<div class='jspsych-instructions-nav'>";
if (current_page != 0 && trial.allow_backward) {
nav_html += "<button id='jspsych-instructions-back' class='jspsych-btn'>< Previous</button>";
}
nav_html += "<button id='jspsych-instructions-next' class='jspsych-btn'>Next ></button></div>"
display_element.append(nav_html);
if (current_page != 0 && trial.allow_backward) {
$('#jspsych-instructions-back').on('click', function() {
clear_button_handlers();
back();
});
}
$('#jspsych-instructions-next').on('click', function() {
clear_button_handlers();
next();
});
}
}
function clear_button_handlers() {
$('#jspsych-instructions-next').off('click');
$('#jspsych-instructions-back').off('click');
}
function next() {
add_current_page_to_view_history()
current_page++;
// if done, finish up...
if (current_page >= trial.pages.length) {
var trial.time_limit = -1; //EDITED
endTrial();
} else {
show_current_page();
}
}
function back() {
add_current_page_to_view_history()
current_page--;
show_current_page();
}
function add_current_page_to_view_history() {
var current_time = (new Date()).getTime();
var page_view_time = current_time - last_page_update_time;
view_history.push({
page_index: current_page,
viewing_time: page_view_time
});
last_page_update_time = current_time;
}
function endTrial() {
for (var i = 0; i < setTimeoutHandlers.length; i++) {
clearTimeout(setTimeoutHandlers[i]);
};
if (trial.allow_keys) {
jsPsych.pluginAPI.cancelKeyboardResponse(keyboard_listener);
};
display_element.html('');
var trial_data = {
"view_history": JSON.stringify(view_history),
"rt": (new Date()).getTime() - start_time
};
jsPsych.finishTrial(trial_data);
}
var after_response = function(info) {
// have to reinitialize this instead of letting it persist to prevent accidental skips of pages by holding down keys too long
keyboard_listener = jsPsych.pluginAPI.getKeyboardResponse({
callback_function: after_response,
valid_responses: [trial.key_forward, trial.key_backward],
rt_method: 'date',
persist: false,
allow_held_key: false
});
// check if key is forwards or backwards and update page
if (info.key === trial.key_backward || info.key === jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.key_backward)) {
if (current_page !== 0 && trial.allow_backward) {
back();
}
}
if (info.key === trial.key_forward || info.key === jsPsych.pluginAPI.convertKeyCharacterToKeyCode(trial.key_forward)) {
next();
}
};
show_current_page();
if (trial.allow_keys) {
var keyboard_listener = jsPsych.pluginAPI.getKeyboardResponse({
callback_function: after_response,
valid_responses: [trial.key_forward, trial.key_backward],
rt_method: 'date',
persist: false
});
}
};
return plugin;
})();
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/8580e004-e913-43a1-a19f-2fefc3722bf3%40googlegroups.com.
I am trying to do the same thing with having a time limit on the instructions plugin, but also having some difficulty. Please let me know, thanks!
--
You received this message because you are subscribed to a topic in the Google Groups "jsPsych" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jspsych/c0yfUy5LGLU/unsubscribe.
To unsubscribe from this group and all its topics, 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/504390ed-1c17-4ac8-8f3c-3da07e867af8%40googlegroups.com.