Youtube Tutorial Stroop Task Pasrt 2

OS (e.g. Win10): Sonoma MacOS
PsychoPy version (e.g. 1.84.x): 2023.2.3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:

I am trying to complete Part 2 of the Stroop task youtube tutorial. However, when I get to a certain part I keep getting the same error:

File “/Users/dm/Documents/Experimental Programmes/Stroop 2/Test_lastrun.py”, line 421, in run
word_list.append(word)
UnboundLocalError: local variable ‘word’ referenced before assignment
################ Experiment ended with exit code 1 [pid:20394] #################

What did you try to make it work?:

I have tried referencing word as a string in the begging section of the code, however, the same issue comes up for ‘colour’ which again I repeat myself and then issues come up for the RGB.

Thanks for any help

Do you have a text component which displayed $word?

It needs to be set to update each repeat and not be constant (set once at the start of the experiment)

Thank you for replying.

I do have $word, however, it is already set to set every repeat.

Does $word appear in any code components? I assume that the routine that references it is inside the loop that points to the spreadsheet.

Word appears in the StroopTrial Component.

curr_item += 1

word = word_list[curr_item]
colour = colour_list[curr_item]

correct_key = colour[0]

Is the code component above the text component or below? It should be above if the code is in Begin Routine.

The code component was below the text, however, I have moved it to the top, yet I am still getting the same error.

The problem comes from the “StimulusLoader” routine within the first loop (“LoaderLoop”). Somehow the variables loaded up by the loader from the excel sheet, are not correctly referenced by the python code. I stumbled exactly on the same problem. For reference, the YouTube tutorial the original poster was referring to is this:

I haven’t been able to find out the cause or the solution to the issue, though.

Ok, I think I found the solution.

It is sufficient to add to the codeLoader element of the initial StimulusLoader routine, the following code lines, under the tab “Begin Experiment”:

global word
global colour