psychopy.org | Reference | Downloads | Github

Urgent- thisexp not defined

Hello all,

When I change “thisExp” to “psychoJS.experiment” one by one in my custom code and sync, until a certain point ı can sync. But after a while when click Sync, I receive this error:

Traceback (most recent call last):
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\builder\builder.py”, line 1344, in onPavloviaSync
self.fileExport(htmlPath=htmlPath)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\builder\builder.py”, line 793, in fileExport
target=“PsychoJS”)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 74, in generateScript
compileScript(infile=exp, version=None, outfile=filename)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 247, in compileScript
_makeTarget(thisExp, outfile, targetOutput)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 219, in _makeTarget
script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment_experiment.py”, line 254, in writeScript
self_copy.flow.writeFlowSchedulerJS(script)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment\flow.py”, line 309, in writeFlowSchedulerJS
resourceFiles = set([resource[‘rel’].replace("\", “/”) for resource in self.exp.getResourceFiles()])
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment_experiment.py”, line 888, in getResourceFiles
thisFile = getPaths(thisParam.val)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment_experiment.py”, line 815, in getPaths
if os.path.isfile(thisFile[‘abs’]):
File “C:\Program Files\PsychoPy\lib\genericpath.py”, line 30, in isfile
st = os.stat(path)
ValueError: stat: path too long for Windows

I check the cribsheet but could not understand what exactly I should do.

You shouldn’t get thisExp is not defined any more in 2021.2.3 if you make an edit to the Python side of an auto component (which will encourage the translation to rerun).

However, I think that the most likely reason for your stat path too long error is the location of your experiment file. Is it in it’s own folder or is it, perhaps, in My Documents with lots of sub folders, all of which you are therefore asking PsychoPy to upload to Pavlovia?

I compiled the JS code and replaced all thisExp with psychoJS.experiment and sync only the JS document (not from builder view) now I am not receiving this error. I think this is not a valid solution.

But I need to figure out why I receive ValueError: stat: path too long for Windows
My experiment document is on the desktop and it only includes my experiment files.

Never edit the JS code directly, unless you know exactly why you can’t make the edit in Builder.

The desktop is not a recommended location. Straight on the desktop (ie not in a dedicated folder) is bound to fail.

I undo all changes. Created new file and carried This PC > Documents location. I am still receiving thisExp error with 2021.2.3 version

Please could you show the relevant code component?

Here is a sample. When I sync, I receive the ValueError: stat: path too long for Windows


Those screenshots look fine. What subfolders are there in the folder with your psyexp file?

That looks fine too. Next please could you show me the full error message for when you sync.

Traceback (most recent call last):
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\builder\builder.py”, line 1344, in onPavloviaSync
self.fileExport(htmlPath=htmlPath)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\app\builder\builder.py”, line 793, in fileExport
target=“PsychoJS”)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 74, in generateScript
compileScript(infile=exp, version=None, outfile=filename)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 247, in compileScript
_makeTarget(thisExp, outfile, targetOutput)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\scripts\psyexpCompile.py”, line 219, in _makeTarget
script = thisExp.writeScript(outfile, target=targetOutput, modular=True)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment_experiment.py”, line 254, in writeScript
self_copy.flow.writeFlowSchedulerJS(script)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment\flow.py”, line 309, in writeFlowSchedulerJS
resourceFiles = set([resource[‘rel’].replace("\", “/”) for resource in self.exp.getResourceFiles()])
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment_experiment.py”, line 888, in getResourceFiles
thisFile = getPaths(thisParam.val)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\experiment_experiment.py”, line 815, in getPaths
if os.path.isfile(thisFile[‘abs’]):
File “C:\Program Files\PsychoPy\lib\genericpath.py”, line 30, in isfile
st = os.stat(path)
ValueError: stat: path too long for Windows

I think that the error message may simply be a result of invalid code.

Please could you add me as a Developer on your study (see my crib sheet for how to do this and unprotect the master branch) and also send me your latest psyexp file via private message

Stat path too long can indicate too many nested if statements. I’ll have a go at simplifying your code later.

Yes, I have nested if statements however I do not know how to simplfy because it was so hard for me to even create this one. Your help is much appreciated.

Bests

Sync the experiment.

Then reopen the psyexp file in PsychoPy.

I solved the stat path error by changing from elifs to ifs

That led to a .remove is not a function error so I’ve created a .remove method for JavaScript

Array.prototype.remove = function(value) {
return this.filter(function(ele){
return ele != value;
});
}

(from 9 Ways To Remove 🗑️ Elements From A JavaScript Array 📇[Examples])

The next error is about language5 (which I think is related to not having the latest spreadsheets).

1 Like

Heyy, thank you so much!!!
Now images are seen like this. They were .jpg format. It was .png before but I changes now the provlem continues

Check which spreadsheet each loop is attached to. While testing I may have pointed loops at old spreadsheets because I didn’t have the new ones.

I updated all the spreadsheets. It works locally

DId it sync? I can’t see the new online version.

Have you used Ctrl-Shift-R or an incognito tab to run the latest version?