Experiments that run flawlessly in older versions of (PsychoPy 2022.2.5) now trigger unbound local errors

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): MAC OS Ventura 13.6.1
PsychoPy version (e.g. 1.84.x): works with 2022.2.5, not with Psychopy 2023.2.3

**What are you trying to achieve?: I have programmed the game Wordle from scratch

**What did you try to make it work?: tried to initialize variables as global

What specifically went wrong when you tried that?:
Still get unbound local errors

Do you have a form component?

Here’s another example of an unbound local error

No the variables are just counters that I have used to count the number of attempts that the person has made in trying to guess the mystery word in Wordle.

In wordle you only get 6 guesses to guess the word, thus if attempt = 6 and the guess is still incorrect it triggers a message saying out of turns…

Please could you show the full text of your error messages?

project/WordleJune27final_lastrun.py", line 8655, in run

attempt = attempt +1

UnboundLocalError: local variable ‘attempt’ referenced before assignment

The full text of the error message is above. Attempt was initialized at the beginning of the experiment. I use it to keep track of how many guesses they have made.

Thanks for looking into this.



Please could you show exactly how you initialised it?

In the working version in 2022.2.5 it was just attempt = 0

I then tried

global attempt

attempt = 0

Here is a screenshot of latest attempt initialization



Put all of that code in Begin Experiment not Before Experiment unless you know why it has to be Before.

Delete global

That seems to have done the trick. If I have to import any libraries, should this be done before the experiment or begin experiment?



I don’t think it matters for importing libraries. I rarely do so, because they don’t work online.