Time limit on viewing instructions

95 views
Skip to first unread message

willia...@gmail.com

unread,
Feb 13, 2018, 2:29:23 PM2/13/18
to jsPsych
Hi all,

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!

Josh de Leeuw

unread,
Feb 13, 2018, 6:27:25 PM2/13/18
to willia...@gmail.com, jsPsych
Hi,

If you use the html-keyboard-response plugin you can set the trial_duration parameter to X ms to set a maximum duration. You loose the ability for participants to navigate forwards and backwards in the instructions, but if that's not critical this is probably the best solution. If it is critical to have a time limit with navigation, it wouldn't be too difficult to modify the instructions plugin to support a maximum time limit by borrowing code from the html-keyboard-response plugin.

Cheers,
Josh

--
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.

willia...@gmail.com

unread,
Feb 19, 2018, 3:09:12 PM2/19/18
to jsPsych

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?

willia...@gmail.com

unread,
Feb 19, 2018, 3:12:38 PM2/19/18
to jsPsych

Nevermind! It looks like one of my modifications to jspsych had screwed this up.

willia...@gmail.com

unread,
Feb 20, 2018, 12:45:35 AM2/20/18
to jsPsych

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'>&lt; Previous</button>";
}
nav_html += "<button id='jspsych-instructions-next' class='jspsych-btn'>Next &gt;</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;
})();

Josh de Leeuw

unread,
Feb 21, 2018, 5:43:49 PM2/21/18
to willia...@gmail.com, jsPsych
I would not try to blend versions of jsPsych that are different major versions (e.g., v5.0.3 with v.6.0.1). Smaller updates (e.g., v6.0 to v6.0.1) will usually be compatible across files. There are too many changes to how plugins are structured with v6 for it to be compatible with v5.

Cheers,
Josh

Josh de Leeuw

unread,
Feb 21, 2018, 5:45:13 PM2/21/18
to willia...@gmail.com, jsPsych
Can you clarify what hasn't worked about just upgrading to the new files? Some of the plugins are renamed for clarity so that may be the problem. If you can explain what error messages you are getting that would help diagnose why it's not working.

jfslo...@gmail.com

unread,
Dec 17, 2018, 8:08:12 PM12/17/18
to jsPsych
Hi - Did you ever get the code that you posted below to work?

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!

William Ryan

unread,
Dec 19, 2018, 9:47:02 PM12/19/18
to jfslo...@gmail.com, jsPsych
I ended up not upgrading to the new jsPsych and just turning my instruuctions into a categorize trial, and then setting its time limit. I think the code posted above should work as long as you are using the most recent JSpsych. 

--
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.
Reply all
Reply to author
Forward
0 new messages