beginner programmer here, so please bear with me.
I keep getting the same error, it says,
UnboundLocalError: local variable 'x' referenced before assignment.
what should I do to solve this?? the code isn't done yet, so for debugging, the values i picked for level is 1, x = 0, y = 8, and direction south.
print("Welcome to the Maze!")
#______________ LEVEL SELECT ______________
level = int(input("Select a Level: 1,2, or 3")) #level select
while level > 3 or level <1:
print("Invalid input. Try again.")
level = int(input("Select a Level: 1,2, or 3"))
grid = level + 2
if level == 1:
maze = [[1,"O",1],[0,0,0],[0,"_",1],
[1,0,0],[0,0,0],[0,"_",1],
[1,0,1],[1,0,0],[0,"X",1]]
elif level == 2:
print("level2")
elif level == 3:
print("level3")
#______________ END OF LEVEL SELECT ______________
location = x = int(input("Select a starting point"))
endpoint = y = int(input("Select an ending point"))
location = maze[x][1]
endpoint = maze[y][1]
#_______________FUNCTION LIST ______________
def moveEast(): #MOVE EAST
if maze[x][2] == 1:
print("Invalid move.")
else:
maze[x][1], maze[x+1][1] = maze[x+1][1], maze[x][1]
x += 1
def moveWest(): #MOVE WEST
if maze[x][0] == 1:
print("Invalid move.")
else:
maze[x][1], maze[x-1][1] = maze[x-1][1], maze[x][1]
x -= 1
def moveNorth(): # MOVE NORTH
if maze[x+grid][1] == "_":
print("Invalid Move.")
else:
maze[x][1], maze[x+grid][1] = maze[x+grid][1], maze[x][1]
x += grid
def moveSouth(): # MOVE SOUTH
if maze[x-grid][1] == "_":
print("Invalid Move.")
else:
maze[x][1], maze[x-grid][1] = maze[x-grid][1], maze[x][1]
x -= grid
#______________END OF FUNCTION LIST______________________
#add available directions
if location != endpoint:
move = input("Which direction will you take?")
if move == "North":
moveNorth()
elif move == "South":
moveSouth()
elif move == "East":
moveEast()
elif move == "West":
moveWest()