URL of experiment:
Description of the problem:
I’m attempting to move my study online with Pavlovia. I am not familiar with Javascript, so I’m having some difficulty translating my code components into js. Specifically, I am getting the following error:
Unfortunately we encountered the following error:
- when getting the position of an object
- when converting a position to pixel units
- unknown position units: undefined
Try to run the experiment again. If the error persists, contact the experiment designer.
I have isolated the error to this every frame code:
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);
if ((! drag_in_process)) {
if (mouse.getPressed(stim_t)) {
clicked_stimulus = stim_t;
drag_in_process = true;
}
}
if (_pj.in_es6(true, mouse.getPressed())) {
if (drag_in_process) {
clicked_stimulus.pos = mouse.getPos();
}
} else {
if ((clicked_stimulus !== null)) {
for (var dest, _pj_c = 0, _pj_a = [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8], _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
dest = _pj_a[_pj_c];
if (dest.contains(mouse.getPos())) {
current_dest = dest;
clicked_stimulus.pos = current_dest.pos;
}
}
clicked_stimulus = null;
} else {
drag_in_process = false;
}
}
if ((! drag_in_process)) {
if (mouse.getPressed(stim_t)) {
clicked_stimulus = stim_t;
drag_in_process = true;
}
}
if (_pj.in_es6(true, mouse.getPressed())) {
if (drag_in_process) {
clicked_stimulus.pos = mouse.getPos();
}
} else {
if ((clicked_stimulus !== null)) {
for (var dest, _pj_c = 0, _pj_a = [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8], _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
dest = _pj_a[_pj_c];
if (dest.contains(mouse.getPos())) {
current_dest = dest;
clicked_stimulus.pos = current_dest.pos;
clicked_stimulus = null;
}
}
} else {
drag_in_process = false;
}
}
The participant is supposed to click and drag the stimulus onto a grid, where it snaps into place. Please let me know where I have gone wrong in my code.
I am adding in my python code that has worked perfectly on local computers.
if not drag_in_process:
if mouse.isPressedIn(stim_t):
clicked_stimulus = stim_t
drag_in_process = True
break
if True in mouse.getPressed():
if drag_in_process:
clicked_stimulus.pos = mouse.getPos()
elif clicked_stimulus is not None:
for dest in [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8]:
if dest.contains(mouse.getPos()):
current_dest = dest
clicked_stimulus.pos = current_dest.pos
clicked_stimulus = None
else:
drag_in_process = False
if not drag_in_process:
if mouse.isPressedIn(stim_t):
clicked_stimulus = stim_t
drag_in_process = True
break
if True in mouse.getPressed():
if drag_in_process:
clicked_stimulus.pos = mouse.getPos()
elif clicked_stimulus is not None:
for dest in [a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8, c1, c2, c3, c4, c5, c6, c7, c8, d1, d2, d3, d4, d5, d6, d7, d8, e1, e2, e3, e4, e5, e6, e7, e8, f1, f2, f3, f4, f5, f6, f7, f8, g1, g2, g3, g4, g5, g6, g7, g8, h1, h2, h3, h4, h5, h6, h7, h8]:
if dest.contains(mouse.getPos()):
current_dest = dest
clicked_stimulus.pos = current_dest.pos
clicked_stimulus = None
else:
drag_in_process = False
Thank you!