# Code works fine offline but does not in Pavlovia

**URL:** <https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427>\
**Category:** Online experiments\
**Tags:** code, pavlovia\
**Created:** [August 6, 2021, 12:32am UTC](https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427 "2021-08-06T00:32:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![correafreisztav](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/correafreisztav/32/30610_2.png) [@correafreisztav](https://discourse.psychopy.org/u/correafreisztav)\
**Post date:** [August 6, 2021, 12:32am UTC](https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427/1 "2021-08-06T00:32:19Z")

</div>

URL of experiment: [tesis [PsychoPy]](https://run.pavlovia.org/Antonella/tesis-2021/)

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;  
}  
}

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/e/ae2dd6bc0689e9ea88f457efe87e24386994a7bc.png)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [August 7, 2021, 8:11am UTC](https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427/2 "2021-08-07T08:11:35Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [August 7, 2021, 10:32am UTC](https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427/3 "2021-08-07T10:32:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [August 7, 2021, 2:49pm UTC](https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427/4 "2021-08-07T14:49:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [August 8, 2021, 7:04pm UTC](https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427/5 "2021-08-08T19:04:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![correafreisztav](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/correafreisztav/32/30610_2.png) [@correafreisztav](https://discourse.psychopy.org/u/correafreisztav)\
**Post date:** [August 8, 2021, 9:31pm UTC](https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427/6 "2021-08-08T21:31:38Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/f/afe0463309815463ca8498b86fe4061f1d3e7d40.png)

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);  
}  
}

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [August 8, 2021, 9:42pm UTC](https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427/7 "2021-08-08T21:42:25Z")

</div>

> [@correafreisztav](#):
>
> puntitos

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 = []`

---

<div class="post-metadata">

**Author:** ![correafreisztav](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/correafreisztav/32/30610_2.png) [@correafreisztav](https://discourse.psychopy.org/u/correafreisztav)\
**Post date:** [August 8, 2021, 10:52pm UTC](https://discourse.psychopy.org/t/code-works-fine-offline-but-does-not-in-pavlovia/24427/8 "2021-08-08T22:52:54Z")

</div>

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

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