URL of experiment: https://gitlab.pavlovia.org/CWoodrow/student_computer_experiment_v1
Description of the problem: When I run my experiment I get an error which says, ‘TypeError: Cannot read property ‘concat’ of undefined’. The error is in a routine which has two code components - one to allow participants to see what they type on-screen, and another to get the key durations for the keys they press. This works in PsychoPy but not in Pavlovia. The first routine that runs as intended contains the same code that allows participants to see what they type, so my assumption is that the error must be in relation to the key duration code, but I can’t figure out what.
Here is what is in my keyDuration code component:
Begin routine
mykb = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: true});
mykb.start();
keysWatched = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
"q","r","s","t","u","v","w","x","y","z","backspace","enter","space",",",
".","/", "backslash", "'",";","[","]","1","2","3","4","5","6","7","8","9","0",
"shift", "capslock", "tab", "control", "alt", "`", "-", "=", "meta", "contextmenu",
"delete", "pound", "arrowleft", "arrowright", "arrowup", "arrowdown", "insert",
"printscreen", "home", "end", "pagedown", "pageup", "pause"];
status = ["up", "up", "up", "up", "up",
"up","up","up","up","up","up","up","up","up","up","up","up","up","up","up","up",
"up","up","up","up","up","up","up","up","up","up","up","up","up","up","up","up",
"up","up","up","up","up","up","up","up","up","up","up","up","up","up","up","up",
"up","up","up","up","up","up","up","up","up","up","up","up","up","up","up","up",
"up"];
keyCount = 0;
currentKey = 0;
statusList = [];
pressTime = 0;
keyPressTime = [];
liftTime = 0;
keyDur=[];
Each frame
// Loop through keyboard events to update keyStates
let keyEvents = mykb.getEvents();
// Get keys?
let keys = mykb.getKeys({keyList: keysWatched, waitRelease: false, clear: false});
key_list = key_list.concat(keys);
// Previous status of key we are currently watching
let previousStatus = status[currentKey];
// Key, timestamp, and keyDown, of current key event
let keyIndex, key, keyStatus;
for (let i = 0; i < keyEvents.length; i++) {
// Current key event
key = keyEvents[i].pigletKey;
keyStatus = keyEvents[i].status === Symbol.for('KEY_DOWN')? 'down': 'up';
// Index of this key in keysWatched. NB findIndex not supported by IE
keyIndex = keysWatched.indexOf(key);
// Key is one that we watch; update its status
if (keyIndex !== -1) {
status[keyIndex] = keyStatus
statusList.append(keyStatus)
console.log('keyStatus')
console.log(statusList)
}
}
if ((statusList.length > 1)) {
if ((statusList.slice((- 1))[0] !== statusList.slice((- 2))[0])) {
if ((statusList.slice((- 1))[0] === "down")) {
pressTime = taskClock.getTime() * 1000
keyPressTime.append(pressTime)
taskClock.reset()
} else {
if ((statusList.slice((- 1))[0] === "up")) {
liftTime = taskClock.getTime() * 1000
keyDur.append(liftTime)
taskClock.reset()
}
}
}
} else {
if ((statusList.length == 1)) {
pressTime = taskClock.getTime() * 1000
keyPressTime.append(pressTime)
taskClock.reset()
}
}
I have tried amending the code in various ways, such as using event.
instead of mykb.
. I have shortened the keysWatched
list to just two keys to see if the issue is related to the key names. I have also tried using .append
instead of .concat
. None of these have helped or changed the error at all.
Any help hugely appreciated! The full JS script can be found in the gitlab link above in the file called ‘StudentExperiment_wordsX2_v6.js’