Its not recognizing the global variable. I experienced this issue before and thought the global variable would prevent the error but no matter what i try it always returns this: local variable 'P1o' referenced before assignment
#import pwinput
import PySimpleGUI as sg
P1o = ("")
P2o = ("")
MAX_ROWS = MAX_COL = 10
def Battleship1():
layout = [
[sg.Text('Player1 please enter your ship positions'), sg.InputText('', size=(10,1), key='input_\P1o')],
[sg.Submit(), sg.Cancel()]
]
window = sg.Window('player1 values', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
elif event == 'Submit':
P1o = P1o.append(int(values['input_\P1o']))
window.close()
elif event == 'cancel':
window.close()
break
layout = [
[sg.Text('Player2 please enter your ship positions'), sg.InputText('', size=(10,1), key='input_\P2o')],
[sg.Submit(), sg.Cancel()]
]
window = sg.Window('player2 values', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == 'Submit':
P1o = P1o.append(int(values['input_\P1o']))
turn()
turn_()
if event == 'cancel':
window.close()
break
""" i set up the multiplayer function"""
layout = [ [sg.Text("Welcome to battleship!!\nObject of the game is to sink all five of your enemy's ships!!!\nlabel your ship positions with a number (0-9)\n and another number (0-9)\n and separate each position with spaces e.g 1,2 2,3 3,4")],
[sg.Button('Single Player'), sg.Button('Multiplayer')] ]
window = sg.Window('Menu', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED:
break
if event == 'Multiplayer':
window.close()
Battleship1()
break