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?
What are you trying to achieve?:
I’m trying to insert a questionnaire into my study to measure dietary restraint.
What did you try to make it work?:
I followed the instructions here: Form Component — PsychoPy v2021.2 and included all elements in the csv file.
What specifically went wrong when you tried that?:
return respHeight / self.win.size[1] + self.itemPadding
UnboundLocalError: local variable ‘respHeight’ referenced before assignment
From a quick google search this does seem to be a …
Here’s another example of an unbound local error
OS (e.g. Win10): mac 10.15.4
PsychoPy version (e.g. 1.84.x): 2020.1.2
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:
I have this old exp that I can still run [github link removed after problem solved ]. I just refactored it: the stimuli are slightly different, but I meant to use the same paradigm [github link removed after problem solved ]. I copied the .psyexp file over, and when I run it, psychopy crushes after instruction presentation and gives me
2020-…
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.
Best
Mike
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
Best
Mike
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?
Best
M
I don’t think it matters for importing libraries. I rarely do so, because they don’t work online.