I am having trouble getting a code component of an experiment to work on Pavlovia. It works perfectly offline. I suspect it has something to do with the translation from Python to JS (see below). Right now I’m stuck with the error message ReferenceError: keys is not defined. I’ve tried defining it in other tabs and with placeholders, but that crashes the experiment. I am new to programming, especially Java, and would be very happy if someone could help me.
Many thanks!
Lori
python code:
stepSize = 1
scale = visual.Slider(win=win,
ticks=(1, 2, 3, 4, 5), size = (1.1, 0.1), labels= None, granularity=1, styleTweaks = ['triangleMarker'], color='white')
scale.reset()
scale.markerPos = random()*5
while not scale.rating:
keys = event.getKeys()
if 'right' in keys:
scale.markerPos += stepSize
if 'left' in keys:
scale.markerPos -= stepSize
if 'down' in keys:
scale.rating = scale.markerPos
scale.draw()
image_15.draw()
image_16.draw()
image_17.draw()
image_18.draw()
image_19.draw()
text_recog.draw()
win.flip()
decisionTime_rat = scale.getRT()
choiceHistory_rat = scale.getHistory()
storeRating = True
storeRatingtime = True
JS
var _pj;
function _pj_snippets(container) {
function in_es6(left, right) {
if (((right instanceof Array) || ((typeof right) === "string"))) {
return (right.indexOf(left) > (- 1));
} else {
if (((right instanceof Map) || (right instanceof Set) || (right instanceof WeakMap) || (right instanceof WeakSet))) {
return right.has(left);
} else {
return (left in right);
}
}
}
container["in_es6"] = in_es6;
return container;
}
_pj = {};
_pj_snippets(_pj);
stepSize = 1;
scale = new visual.Slider({win:psychoJS.window, ticks:[1, 2, 3, 4, 5], size:[1.1, 0.1], labels:null, granularity:1, styleTweaks:["triangleMarker"], color: "white"});
scale.reset();
scale.markerPos = (Math.random() * 5);
while ((! scale.rating)) {
keys:psychoJS.eventManager.getKeys();
if (_pj.in_es6("right", keys)) {
scale.markerPos += stepSize;
}
if (_pj.in_es6("left", keys)) {
scale.markerPos -= stepSize;
}
if (_pj.in_es6("down", keys)) {
scale.rating = scale.markerPos;
}
scale.draw();
image_15.draw();
image_16.draw();
image_17.draw();
image_18.draw();
image_19.draw();
text_recog.draw();
}
decisionTime_rat = scale.getRT();
choiceHistory_rat = scale.getHistory();
storeRating = true;
storeRatingtime = true;