Trying to create the following experiment: subject sees a list of four categories, selects one of the categories, and sees an image from that category. (There's more complication after that with limiting the number they can see from each category etc, but I'm still stuck on this first step).
I'm trying to use a single-stim trial to store a key press (either a, b, c, or d) and then to store that key press in a variable. (I'll later use that variable to point to an array that will lead to the images for the particular category.) So far, I've been trying to use getLastTrialData to access which key was pressed during the category selection block, and store that info in the global last_input var. But, I can't get the value of last_input to update to the numeric key code for the key pressed. Here's my code; any insights?
<!doctype html>
<html>
<head>
<title>singlestimtest</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="jspsych-4.2/jspsych.js"></script>
<script src="plugins/jspsych-single-stim.js"></script>
<script src="plugins/jspsych-text.js"></script>
<link href="jspsych-4.2/css/jspsych.css" rel="stylesheet" type="text/css">
</head>
<body>
</body>
<script>
var last_input = 10;
var welcome_block = {
type: "text",
text: "In a moment you will select a category. Press any key to continue."
};
var categories_block = {
type: 'single-stim',
stimuli: '<p>A B C D</p>',
is_html: true,
choices: ['a', 'b', 'c', 'd'],
response_ends_trial: true,
};
var get_response = {
type:'single-stim',
stimuli: 'press space to see response',
is_html: true,
choices: [' '],
on_finish: function(data) {
alert('working too!');
last_input = jsPsych.data.getLastTrialData();
return last_input;
}
};
var thankyou_block = {
type: "text",
text: "Thanks for participating" + last_input
};
var experiment = [];
experiment.push(welcome_block);
experiment.push(categories_block);
experiment.push(get_response);
experiment.push(thankyou_block);
jsPsych.init({
experiment_structure: experiment,
on_finish: function() {
jsPsych.data.displayData();
}
});
</script>
</html>
Thanks in advance!
Emma
--
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/3a163edc-404b-42f5-986a-b2bcb1e5e126%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.