Experiment stuck on 'Initializing Experiment'

Code: Rebecca Lysaght / serial dependence · GitLab

Description of the problem:

Hi, I have an experiment that works locally but doesn’t run in Pavlovia. There are a couple of issues based on what I’ve read about what Pavlovia doesn’t support (I need to change some of the color values to [1,255] and some of the deg layouts to height) but the main issue I don’t know how to solve is how to replace one of my code components. It looks like this:

import {key} from ‘pyglet/window’;
var keyState;
keyState = new key.KeyStateHandler();

keyState = new key.KeyStateHandler();
notFinished = true;

imgNum = util.randint(1, 147);
imageFile = ((“female/” + imgNum.toString()) + “.bmp”);
MatchFace.setImage(imageFile, {“log”: false});
while ((notFinished === true)) {
wobmp = imageFile.slice(0, (- 4));
img = Number.parseInt(wobmp.slice(7));
psychoJS.window.winHandle.push_handlers(keyState);
if (keyState[key.LEFT]) {
if ((img === 1)) {
imageFile = “female/147.bmp”;
} else {
imageFile = ((“female/” + (img - 1).toString()) + “.bmp”);
}
MatchFace.setImage(imageFile, {“log”: false});
}
if (keyState[key.RIGHT]) {
if ((img === 147)) {
imageFile = “female/1.bmp”;
} else {
imageFile = ((“female/” + (img + 1).toString()) + “.bmp”);
}
MatchFace.setImage(imageFile, {“log”: false});
}
if (keyState[key.SPACE]) {
AdjTime = clock.getTime();
notFinished = false;
continueRoutine = false;
}
if (keyState[key.ESCAPE]) {
core.quit();
}
psychoJS.window.flip();
}

Basically on every right or left click I want to update my image component and on space I want to stop taking keyboard input and move on to the next loop. I read that Pavlovia doesn’t support KeyStateHandler but what can I replace it with? My understanding of the Keyboard component in the Builder is that it stores/returns all keys pressed - I need a way to pause after every key press (could be anywhere from 1 to over a hundred) to update the image component.

Any help would be greatly appreciated, thank you.

Do you just need to use keys=event.getKeys() in each frame and add code for what to do if ‘left’ in keys: etc.?

Thanks for the response! I’m not sure about the ‘each frame’ part. Is a frame a period of time between clicks or is it a fixed rate that the screen refreshes at? Basically on every click I need to check event.getKeys() to see what was clicked and take action. I was thinking of trying event.getKeys(), looking for ‘left’ ‘right’ ‘space’ or ‘esc’, performing the logic associated with whichever key is clicked, then clearing the keys list for the next click? Another alternative might be storing all the keys and always accessing the last one in the list?

Are you using Builder?

Each Frame is a tab of a code component which repeats once per screen refresh (or slower if there is too much going on).