| Reference | Downloads | Github

Require is not defined in PsychoJS

URL of experiment:

Description of the problem
My idea is simple. I want to counterbalance different conditions. For this I want the program to check the amount of output files. And if this number is odd then condition1 = True else Condition2 = True.
In python it is not that difficult to achieve. The code looks like this and it works fine:

import fnmatch
number = len(fnmatch.filter(os.listdir(‘data’), ‘*.csv’))
if (number % 2 ) == 0:
thisIndex = 1
thisIndex = 2

However, PsychoJS is another story. what I’ve come up with is the following:

fs = require(‘fs’);
fs.readdir( ‘data’, (error, files) => {
let totalFiles = files.length; // return the number of files

if ((totalFiles % 2 == 0)) {
thisIndex = 1;
} else {
thisIndex = 2;
it says require is not defined. Apparently require is not support online. Can somebody help me to make
PsychoJS to count the number of output file in the data folder and assign it to a variable?

I can’t help with require (apart from not being surprised that it doesn’t work). However, I can help with counterbalancing. I’ve just written a web app. for it which anyone can use.

Best wishes,