I have created a function that provides a memory game using NeuroTask scripting (Java Script). Unfortunately, the experiment stops when the user clicks by accident outside of the squares the user is supposed to click on. I need help with finding a solution so the experiment does not stop and preferably ‘pretends’ like nothing happened. The game only continues when one of the squares is clicked that needs to be clicked.
Does anyone know how I can solve my proplem? Is it anything that needs to be changed inside the TheGame function or outside of the function? I was trying to use asynchronous programming, but I could’t make it work.
This is what I have so far…
var coords = [[28.5,53],[39.5,53],[50.5,53],[61.5,53],
[28.5,64],[39.5,64],[50.5,64],[61.5,64],
[28.5,75],[39.5,75],[50.5,75],[61.5,75],
[28.5,86],[39.5,86],[50.5,86],[61.5,86]];
var blocks = [];
//var series = shuffle(range(16)); // no underlying pattern condition:
//var series = [1,3,12,8,9,7,4,15,13,14,0,5,11,2,6,10]; // pattern
//var series = range(16);
function Controller()
{
for (i = 0; i < coords.length; i++) // Create block layout, use `i` as id
{
blocks.push(main.addblock(coords[i][0],coords[i][1],10,10,"black","",i));
}
}
function TheGame(){
var series = [];
if (subject_id % 2 === 0)
{
log(0, "Condition");
series = shuffle(range(16));
log(series, "Series_Condition");
} else {
log(1, "Condition");
series = [1,3,12,8,9,7,4,15,13,14,0,5,11,2,6,10];
}
for (u = 0; u < 15; u++)
{
var learning = [];
//var series = [1,3,12,8,9,7,4,15,13,14,0,5,11,2,6,10];
trial_block.text("Trail: " + (u+1));
trial_block.style("italics");
//await(1500);
//s_block.clear();
for (i = 0; i < 16; i++) // Have subject click series
{
s_block.showimage(stimulus[i]);
e = await("click"); // Event `e` also contains target node
b = parseInt(e.event.target.id); // parseInt turns a string into a number
log(b, "ID");
blocks[b].blink("green",250); // 250 ms blink to black
if (series[i] !== b) // Count errors
{
blocks[b].blink("red",250);
learning.push(b);
}
}
var win = 16 - learning.length;
log(win, "Score");
//s_block.text("You have " + win + " correct!");
//await(1500);
//s_block.clear();
}
}