I am making a simple game in pygame, with a structure something like this:
def mainmenu():
...
def gameloop()
...
[initialising Pygame, making the window, etc]
mainmenu()
gameloop()
This is the problem. Now in the function gameloop() there is a variable 'MOUSE_X' which is set to the X position of the mouse.
When I only run just the mainmenu() function or just the gameloop() function, the program works fine.
However, when I run the two functions in succession, I get the error:
**UnboundLocalError: local variable 'MOUSE_X' referenced before assignment**
The local variable 'MOUSE_X' only exists in the gameloop() function and is not referenced outside of that function. I've gone through the program and confirmed this multiple times.
Why am I getting this error?