📝 Description
game_loop() in Snake-Game.py reads and reassigns game_state, score, level, speed, and high_score without declaring them as global inside that nested function. Because Python sees an assignment to these names somewhere in the function body, it treats them as local variables for the entire function — so the very first read of game_state (before any local assignment has happened) raises an UnboundLocalError. This crashes the game almost immediately after it starts running.
🪜 Steps to Reproduce
- Go to
games/Snake-Game/
- Run script
python3 Snake-Game.py
- Press SPACEBAR to start the game, then either let the snake hit the border/itself, or eat food to trigger a score update
- See error
🎯 Expected Behavior
The snake game should run normally — tracking score, level, speed, and game state changes (IDLE → PLAYING → PAUSED/GAME_OVER) without crashing.
💻 Environment
- OS: [e.g. Windows 11, macOS, Ubuntu]
- Python Version: [e.g. 3.10.x]
- File Name: games/Snake-Game/Snake-Game.py
📝 Description
game_loop()in Snake-Game.py reads and reassignsgame_state,score,level,speed, andhigh_scorewithout declaring them asglobalinside that nested function. Because Python sees an assignment to these names somewhere in the function body, it treats them as local variables for the entire function — so the very first read ofgame_state(before any local assignment has happened) raises anUnboundLocalError. This crashes the game almost immediately after it starts running.🪜 Steps to Reproduce
games/Snake-Game/python3 Snake-Game.py🎯 Expected Behavior
The snake game should run normally — tracking score, level, speed, and game state changes (IDLE → PLAYING → PAUSED/GAME_OVER) without crashing.
💻 Environment