-
Hi Guys! This is my first experiment with jspsych. Background: I have ended up with setInterval: The "display" element is an HTML span element updated every 100 ms with the A_counter JS variable. by innerHTML method. A_counter is a global variable increased with each key-press (I know that its correctly defined and updating accordingly) This solution is not elegant or efficient, especially that I would like to add some additional counters for other keys and I would need to add also additional setInterval functions. Problem:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi!
|
Beta Was this translation helpful? Give feedback.
-
If you want the display to be updated with the current value of your variable as it is updated during a single trial, then I think you'll want to use a keyboard event handler (as @Aodarium suggested). This allows you to do something in response to any keyboard event.
Does this mean you already have a keyboard event handler that is capturing these key presses and incrementing a counter? If so, then inside that same event handler, you could update the display as well. And if you want to add some additional counters for other keys, you could do that all in the same event handler. Something like this (not tested): var A_counter = 0;
var B_counter = 0;
document.addEventListener('keydown', function(e) {
if (e.key == 'a') {
A_counter++;
document.getElementById("display_A").innerHTML = A_counter;
} else if (e.key == 'b') {
B_counter++;
document.getElementById("display_B").innerHTML = B_counter;
}
}); |
Beta Was this translation helpful? Give feedback.
Hi!
on_start: function(){ (document.getElementById("display").innerHTML = A_counter; })
In case you want to change the value of an already existing trial/slide, you could do something like
on_start: function(SLIDETOCHANGE){ (SLIDETOCHANGE.stimulus = A_counter; })