No normally you shouldn’t have to define variables explicitly if they are spreadsheet column headers. However, there’s something in your code that is trying to access it before the spreadsheet is read into PsychoPy. Could you locate which line is triggering this ReferenceError? That might help diagnose why is the line incorrectly trying to reference this variable before it exists.
Here is your code:
If I use Experiment / Find in Experiment and search for direction, the only other appearance is in a comment (code_spot each frame)
direction is set to one of two pieces of text within an if clause and then used outside it (to construct msg). Put direction = '' in line 9 to define it outside the clause.
Your loop points to a conditions file with an absolute path “/Users/ilkekavusturan/Desktop/son/prac_trials.xlsx”. Your desktop doesn’t exist online. I would recommend moving your son folder to a documents area and then reattaching the spreadsheet with a relative path (just prac_trials.xlsx)
Try an incognito tab to check you’re using the latest version of the code.
Check which line of code is giving the error (e.g. 1490 in your screenshot – if you click on it you’ll see what line it is)
Line 359 in your screenshot says “Run Begin Experiment code from code_3”
Have a look at your code_3 code component. The second line is trying to use line_rect_len before the loop has started. That code looks more like it should be in Begin Routine.
I get * ReferenceError: direction is not defined when its in begin routine
Have you done this?
direction is set to one of two pieces of text within an if clause and then used outside it (to construct msg). Put
direction = ''in line 9 to define it outside the clause.
You could also put it in any routine that occurs earlier in the experiment or Begin Experiment of any routine.
Sorry, I missed that one. It works perfectly now. Thank you so much.


