psychopy.org | Reference | Downloads | Github

Code works fine offline but does not in Pavlovia

URL of experiment: tesis [PsychoPy]

Description of the problem: The experiment has some code that works fine in python. However, when trying to run it on Pavlovia, “append” function seems not to work as expected. I leave here every code used (in case you found another future mistake)

In every trial (python):
contador2 += 1
if not flechas_3.keys:
feedback = “muy lento!”
elif flechas_3.keys == str(correct_key):
feedback = “bien hecho :)”
puntitos2.append(1)
else:
feedback = “error :(”
puntitos2.append(0)

(js):
contador2 += 1;
if ((! flechas_3.keys)) {
feedback = “muy lento!”;
} else {
if ((flechas_3.keys === correct_key.toString())) {
feedback = “bien hecho :)”;
puntitos2.append(1);
} else {
feedback = “error :(”;
puntitos2.append(0);
}
}

Later, I will use this other code (that I’m not sure if will work)

if contador >= 30:
if sum(puntitos[-28:])/30 >= 0.93:
trials.finished = True

if ((contador >= 30)) {
if (((sum(puntitos.slice((- 28))) / 30) >= 0.93)) {
trials.finished = true;
}
}

Have a look at my crib sheet.

append needs to be translated to push for online use. However, this can be done once at the start of the experiment instead of every time if you don’t have editable text boxes (or possibly if you use the latest version)

Or alternatively use the newest release if you can (depending how deep you are into making the experiment!) - the translations will be much smoother - append included!

Becca

From what version is Polyfill included? I heard that it missed 2021.2.0.

I think it should have been in that release - but can confirm it is in 2021.2.2 (and I would recommend downloading that one, or 2021.2.3 if on mac, if you are making the big switchover!)

Becca

hi again, I tried again in 2021.2.2. now this comes out. Im a bit lost

this is the new code

contador += 1;
if ((! flechas.keys)) {
feedback = “muy lento!”;
} else {
if ((flechas.keys === correct_key.toString())) {
feedback = “bien hecho”;
puntitos.push(1);
} else {
feedback = “error”;
puntitos.push(0);
}
}

That means that the thing you are trying to append/push isn’t defined yet is there a place in your code that you initialize the variable? i.e. puntitos = []

Oh, thank you very much! So sorry for the silly question.

I was using “puntitos = list()” instead of "puntitos = [ ]