| Reference | Downloads | Github

Task on pavlovia not finding coded variables

URL of experiment:

Description of the problem: I am designing a simple task where participants see a definition and are asked to come up with a word that describes it. The task works perfectly in builder on my computer. But when I upload it on pavlovia, it gives me an error saying “captured_string” is not defined – captured_string is the variable I defined inside the code chunk, so that the participant can see what they are typing. I have defined it in the beginning of the experiment so I’m not sure why pavlovia cannot find it. I don’t have any JS code inside my files though, but I am not sure what to add in there. Any help would be appreciated, thank you!

Here are the psyexp and excel file to go with the experiment.

TOTOnline.psyexp (71.8 KB)

TOTstimuli.xlsx (9.2 KB)

That is the issue. For every snippet of custom Python code you have in your code components, you need to provide a JavaScript equivalent in order to get that same functionality online.

In your code components, change the “code type” pop-up menu button from Py to Both so that you can see windows for each language simultaneously, and work through translating the snippets one at a time.

Hi Michael, thanks for your reply! I have now been able to add the JS code and run the experiment. I had a follow-up question. I am trying to generate a random code for each participant that they can later provide me with so I can check their data. This random code is displayed on the final screen of the experiment, but I’m trying to store this in the csv for each participant and it doesn’t seem to work.

I used this code in the begin routine (JS) tab:

SID_name = Math.floor(Math.random()*100000);
string_sid = String(SID_name);
SID_name_final = "TOTDone_".concat(string_sid);

and am using this code in the end routine tab:

psychoJS.experiment.addData("SID_final", SID_name_final);

Am I missing something? This same type of code has worked for all other variables in my experiment, so I’m not sure what is different here.

Attached are the experiment files
TOTfinal.psyexp (60.9 KB)
TOTstimuli.xlsx (9.2 KB)

Thanks in advance!

I’m not much of a JavaScript person so am unlikely to be able to assist anyway, but providing more detail than that will be the first step in getting a useful answer…

Hi Michael, sorry if I wasn’t clear before. Essentially, I was hoping to get a column in the final csv for the experiment that would store the “SID_name_final” variable. But that is not happening – after the final screen, the experiment basically ends and I can see all the data up until this line in the csv.

The experiment is here for your reference:


Hi @abhilashak9, this is an issue with orphaned data not being collected and saved when a routine is not in a loop, or does not precede a loop. There are two fixes 1) you could uprade to PsychoPy 3.1.5, which has the fix included in the JS, or 2) you could encase your final routine, which saves the data, into a loop that has 1 iteration.

Hi @dvbridges, upgrading to PsychoPy 3.1.5 worked, thank you so much!