URL of experiment: dscrimination [PsychoPy]
dscrimination.py (134.5 KB)
Description of the problem: when I add the following code component into my experiment, it couldn’t finish the initialisation online but it runs offline. The check page shows "Uncaught SyntaxError: unexpected token ‘var’ ".
Could anyone help me with it? I have checked all the relevant topics but still can’t solve this problem.
if choose_2.status == FINISHED:
k = ""
for key in choose_2.keys[:-1]:
k = k + key
if k == '1':
opt1_2.color = 'green'
elif k == '2':
opt2_2.color = 'green'
elif k == '3':
opt3_2.color = 'green'
elif k == '4':
opt4_2.color = 'green'
elif k == '5':
opt5_2.color = 'green'
elif k == '6':
opt6_2.color = 'green'
elif k == '7':
opt7_2.color = 'green'
elif k == '8':
opt8_2.color = 'green'
elif k == '9':
opt9_2.color = 'green'
elif k == '10':
opt10_2.color = 'green'
elif k == '11':
opt11_2.color = 'green'
elif k == '12':
opt12_2.color = 'green'
elif k == '13':
opt13_2.color = 'green'
elif k == '14':
opt14_2.color = 'green'
elif k == '15':
opt15_2.color = 'green'
elif k == '16':
opt16_2.color = 'green'
elif k == '17':
opt17_2.color = 'green'
elif k == '18':
opt18_2.color = 'green'
elif k == '19':
opt19_2.color = 'green'
elif k == '20':
opt20_2.color = 'green'
dscrimination.py (134.5 KB)
the first lines of the following two sets of code are where the error report points at. I am completely ignorant about codes, so bear with me, please. if you need more info about the experiment, please leave a comment. I’ll reply to you right away!
if (choose_2.status === PsychoJS.Status.STARTED && Boolean(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);
_pj.in_es6("g", choose_2.keys))) {
choose_2.status = PsychoJS.Status.FINISHED;
}
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;
}
I’m not seeing this error when I check your link.
Instead I get (later) * TypeError: Cannot use ‘in’ operator to search for ‘undefined’ in undefined
The issue is with this code
if (choose_2.status === PsychoJS.Status.STARTED && _pj.in_es6(choose_2.keys)) {
choose_2.status = PsychoJS.Status.FINISHED;
}
However, this doesn’t seem to match up with your Python code. Are you using an Auto translate code component?
You uploaded a .py file rather than a .psyexp file, so I can’t investigate further.
1 Like
Thank you for your prompt reply! Yes, I solved the last issue, but it came up with other more problems. The JavaScript is losing almost all the definition codes? (var ****), but the python code is totally ok and the experiment can run on my laptop perfectly. I added all the variables myself in the Javascript. Now the problem is TypeError: Cannot use ‘in’ operator to search for ‘undefined’ in undefined , which I couldn’t find any solution.
dscrimination.psyexp (181.9 KB)
// *opt4_2* updates
if (t >= 0.0 && opt4_2.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
opt4_2.tStart = t; // (not accounting for frame time here)
opt4_2.frameNStart = frameN; // exact frame index
opt4_2.setAutoDraw(true);
}
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);
keys = psychoJS.eventManager.getKeys();
if (keys.length) {
if (_pj.in_es6("left", keys)) {
slider_2.markerPos = (slider_2.markerPos - 1);
} else {
if (_pj.in_es6("right", keys)) {
slider_2.markerPos = (slider_2.markerPos + 1);
}
}
}
psychoJS.experiment.addData("Rating", slider_2.markerPos);