Hi everyone.
I am trying to adapt a drag & drop code (Drag & Drop Stimuli - #6 by dvbridges) to work online.
The py code:
def movePicked(picked, newmouse, grabbed):
# Move piece if we already moving that piece
if grabbed is not None and newmouse.isPressedIn(grabbed):
grabbed.pos = newmouse.getPos()
return grabbed
else:
# Move newly clicked piece
for piece in picked:
if newmouse.isPressedIn(piece) and grabbed is None:
return piece
The auto translated js code:
function movePicked(picked, newmouse, grabbed) {
if (((grabbed !== null) && newmouse.isPressedIn(grabbed))) {
grabbed.pos = newmouse.getPos();
return grabbed;
} else {
for (var piece, _pj_c = 0, _pj_a = picked, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
piece = _pj_a[_pj_c];
if ((newmouse.isPressedIn(piece) && (grabbed === null))) {
return piece;
}
}
}
}
When I run the experiment I got the error ReferenceError: movePicked is not defined
Following the instruction on this discussion (Manually defined functions don't work when running experiment online) I changed the js code accordingly:
function = movePicked(picked, newmouse, grabbed) {
if (((grabbed !== null) && newmouse.isPressedIn(grabbed))) {
grabbed.pos = newmouse.getPos();
return grabbed;
} else {
for (var piece, _pj_c = 0, _pj_a = picked, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
piece = _pj_a[_pj_c];
if ((newmouse.isPressedIn(piece) && (grabbed === null))) {
return piece;
}
}
}
}
But now if I run the experiment it gets stuck on “initializing the experiment”.
What is wrong?