I got this error while making a simple poker game :
Traceback (most recent call last):
File "main.py", line 366, in <module>
startFunc()
File "main.py", line 362, in startFunc
botAct()
File "main.py", line 305, in botAct
if yourTurn == False:
UnboundLocalError: local variable 'yourTurn' referenced before assignment
Here is my code at line 305 :
def botAct():
if yourTurn == False:
action1 = random.randint(1,4)
if action1 == 1:
bot1Fold()
yourTurn = False
elif action1 ==2:
bot1Check()
yourTurn = False
elif action1 ==3:
bot1Raise()
yourTurn = False
elif action1 ==4:
bot1Call()
yourTurn = False
The code repeat itselfs after that with just the name of the bots changing (ex. bot1 become bot2 and action1 becomes action2)
I named the variable before at line 16 : yourTurn = True
The program is supposed to, when someone plays, change the value of the yourTurn variable. If the bot plays, then it becomes True because it is now your turn to play but if you play then it becomes False because it is not your turn to play.
I used this variable almost everywhere in my program. I made it in Repl.it. Here is the link : Repl program