Skip to main content

Saving Data

Schema

All data must be defined in the schema. We use this schema:

const schema = {
trial_index: {
type: "integer",
description: "Index of the trial within this assessment, 0-based.",
},
congruent_stimulus: {
type: "boolean",
description: "Did the word displayed on the screen match its font color?",
},
response_time_ms: {
type: "number",
description: "Time in milliseconds between when the word appears and the user taps a response button.",
},
response_correct: {
type: "boolean",
description: "Was the user's response correct? (Did the button response match the font color).",
}
};

Timing the user

How long the user takes to respond is important. This response time will be the duration from when the word appears until when the user taps a response button. We start a timer in the same Action in which we make the word visible and the response buttons enabled.

Action.custom( {callback: () => {
redButton.hidden = false;
greenButton.hidden = false;
blueButton.hidden = false;
wordLabel.text = trialConfigurations[game.trialIndex].word;
wordLabel.fontColor = trialConfigurations[game.trialIndex].color;
redButton.isUserInteractionEnabled = true;
greenButton.isUserInteractionEnabled = true;
blueButton.isUserInteractionEnabled = true;
Timer.startNew("rt");
}})

We stop the timer in the handleResponse event handler for the button taps, and store the elapsed time in the variable responseTime.

function handleResponse(buttonColor) {
Timer.stop("rt");
const responseTime = Timer.elapsed("rt");
...

Saving data for the trial

Because the button tap is the end of all the user's behavior for this trial, at this point we have all the data on this trial. In the handleResponse event handler, save the trial data for each of the measurements in the schema.

function handleResponse(buttonColor) {
Timer.stop("rt");
const responseTime = Timer.elapsed("rt");
game.addTrialData("trial_index", game.trialIndex);
game.addTrialData("response_time_ms", responseTime);
Timer.remove("rt");
game.addTrialData("congruent_stimulus", trialConfigurations[game.trialIndex].congruent);
if (buttonColor === trialConfigurations[game.trialIndex].colorString) {
game.addTrialData("response_correct", true);
} else {
game.addTrialData("response_correct", false);
}
...

Progress so far

The assessment now saves data for each trial. When the user completes the assessment, however, the end scene does not yet display the feedback results.

Loading...