psychopy.org | Reference | Downloads | Github

frameDur not defined

URL of experiment: https://pavlovia.org/Hunter/object-location-task

Description of the problem:
Reference Error: frameDur not defined

The experiment contains one code component and I used autoJS to translate it to JS.

Code can be found here:
OL_SESSION 1(pix).psyexp (111.2 KB)

Any help much appreciated!

Best wishes,
Tom

Hi Tom,

Tried to look at your code component but I get the error “ValueError: <psychopy.experiment.params.Param object at 0x000001A72345B438> is not in list”. Perhaps try deleting it and adding it again?

I had a similar issue before when I tried to code in JS. For myself when declaring variables such as frameDur make sure it doesn’t have “var” before it. This can means its only available within that routine. For example, if you have “var frameDur = 1000;” in “begin experiment”, it will become inaccessible for any following routines. Instead, you can put it directly where its needed in “begin routine”.

Hope that was slightly helpful

Chris

Hi Chris,

Thanks for getting back to me.

I’ve included the js (the python code works just fine and I used py>autojs so Ii’m lost at sea by this point haha!)

Best wishes,
Tom

current link:

Hi Tom,

Someone else got the same error have you checked this post: frameDur is not defined error ? I think they managed to sort it.

Chris

thanks i sorted that one based on the thread you suggested.

NOTE* for complete newbies - it took me a while to figure out how to even edit the js script because you don’t seem to be able to do it using the Edit option, when I clicked “Web IDE” it let me edit the script.

on to the next error: ReferenceError: INTROClock is not defined hahahaha!

Thanks,
Tom

So, a bit of background about the general issue with this error. Variables in JS have to be defined before use and where that definition is inserted defines their scope. A part of the Builder->JS compile step is to detect the variables and add in their definitions at a global level so that they are accessible throughout the study.

I think the fact that some studies are reporting this (but most are not having the problem) I think is probably a symptom of another problem in the experiment that isn’t showing up in a very clear way :frowning: So I’m thinking that some part of the study is failing to generate correct JS code (I don’t know why and it might well not be your fault) and therefore the second step of finding all the variables is failing.

When you export your HTML/JS code from the study (e.g. with sync) is there no warning/error message showing up I suppose? Sorry, I haven’t had a chance to check your experiment myself yet, but the general steps would be trying to simplify the study down until the error goes away so that we can work out which part is the root cause. Once we find the root cause in one or two of these studies we can hopefully add something that traps it and saves other users from the issue

Hi Jon,

Thanks for this - it seems to want me to define about 20 variables on my own. I’ve been working my way through them fine until I got to one that when I define it in the same way as the others it doesn’t work and I get the same error.

Reference Error: Where is not defined.

the attached image shows of all of the variables i’ve successfully manually added in the black circle and the one with the red arrow pointed to it doesn’t work even though it seems to point to the right variable (i.e., it is highlighted elsewhere in the code when i click it).

Potentially useful information: I have an easier version of the task which works fine, its only the version with the code component which has issues. And i’m using 2020.1

Best wishes,
Tom

syntax error 800A03EA

Yes, very important info, and that fits my theory.

Adding those variables is one thing (the symptom) but the true cause is most likely a syntax error in the code component. If the rest of the program were right then they would have been created automatically for you. Most likely something in your python code got auto-translated incorrectly (because that isn’t easy to do right!).

Could you upload your CodeComponent in both Python and the translation. Please use 3 backticks ``` to surround the code when you post it so that it keeps the formatting.

cheers,
Jon

I wasn’t sure how to best send the code so I just went for screenshots, apologies if that is inconvenient.

Please find attached the python code and the autoJS code.

The code works fine locally.

Cheers,
Tom

Dear all, I have encountered a similar issue. I had previously coded an experiment in Coder (only .py file) and wanted to port it to Pavlovia. As I am not fluent in JS I thought I use a trick to put in a Code Component and then copy-paste some of my .py program code through the Code Component. I managed to push my way through many debugging steps, but ultimately get stuck on ReferenceError messages, including the “frameDur” reference.

URL: https://pavlovia.org/VinVen/pavloviacodertest1 (but I continuously keep up updating the .js file in HTML in an attempt to reach a stable version)

I use Psychopy3 v.2020.1.2 on a Macbook.

Would it perhaps help if I put much additional code as functions in a separate .py file and import it in the .psyexp experiment? I may still need the Code Component for this, but could put it at the end of the experiment?

Many thanks and kind regards,
Vincent.

@jon – I have the same issue and thought to comb through my code statements.
I suspect this one could be a suspect, since another experiment complains about it directly:

FP_Duration = (0.5 + (0.5 * np.random.random()));

Does np still work / can you use it for js?

The URL for my study is

https://run.pavlovia.org/MJB/fapesp-time_estimation/html/

numpy (abbreviated as np in Builder scripts) is a Python library and doesn’t exist in Javascript.

Instead of np.random.random() you could try the Javascript function Math.random(), which should be roughly equivalent.

1 Like