So I'm just learning python still, and I've got this assignment to make a maze program (no graphics or any of that, just a text based one) and I'm trying to get it working, but the function I've written to find the legal moves keeps throwing errors.

The most recent one its thrown is TypeError: 'NoneType' object is unsubscriptable
I'll post the code below (not the whole thing, just the bits relevant to this bit cause the whole thing is over 200 lines). If someone out there could tell me how to fix it it would be GREATLY appreciated. Thank you :D

def get_legal_directions(maze, (row,col)):
    legals=[]
    if maze[row-1,col] == 'O' or 'F':
        legals.append('N')
    elif maze[row+1,col] == 'O' or 'F':
        legals.append('S')
    elif maze[row,col+1] == 'O' or 'F':
        legals.append('E')
    elif maze[row,col-1] == 'O' or 'F':
        legals.append('W')
    return legals

def interact():
    maze = load_maze(raw_input("Maze file:"))
    (row,col)=1,1
    print "You are at position",(row,col)
    Log=[(1,1)]
    while True:
        command=raw_input ("Command:")
        if command in "?NSEWRBLQ":
            if command in "NSEW": 
                position= move.__get__(pos)            ###__get__ is close but not it...###
                if 'S' in getLegal:
                    movex = move(maze,(row,col),command)
                    Log.append(position)
                    if maze(row,col) == 'F':
                        return "Congratulations - you made it!"
                    else:
                        print "You are at position",Log[-1]

                elif 'N' in get_legal_directions(maze,(row,col)):
                    movex = move(maze,(row,col),command)
                    Log.append(position)
                    if maze(row,col) == 'F':
                        return "Congratulations - you made it!"
                    else:
                        print "You are at position",Log[-1]

                elif 'W' in get_legal_directions(maze,(row,col)):
                    #getpos=get_position_in_direction((row,col),"W")
                    movex = move(maze,(row,col),command)
                    Log.append(position)
                    if maze(row,col) == 'F':
                        return "Congratulations - you made it!"
                    else:
                        print "You are at position",Log[-1]

                elif 'E' in get_legal_directions(maze,(row,col)):
                    movex = move(maze,(row,col),command)
                    Log.append(position)
                    if maze(row,col) == 'F':
                        return "Congratulations - you made it!"
                    else:
                        print "You are at position",Log[-1]
            elif command=='Q':
                areyousure = raw_input("Are you sure? [y/n]:")
                if areyousure == 'y':
                    break
                else:
                    continue
        else:
            print "Invalid Command:",command  


def move(maze,(row,col),direction):
    position=(row,col)
    can_move = False
    is_finished = False
    if direction == 'E':
        get_position_in_direction((row,col),'E')
    elif direction == 'N':
        get_position_in_direction((row,col),'N')
    elif direction == 'S':
        get_position_in_direction((row,col),'S')
    elif direction == 'W':
        get_position_in_direction((row,col),'W')
    if maze(row,col) in 'OF':
        move_legal = True
        if maze(row,col) in 'F':
            is_finished = True
            return can_move,is_finished,new_position
        else:
            return can_move,is_finished,position
    else:
        return can_move,is_finished,position

Edited 4 Years Ago by deceptikon: Fixed code tags

Also sorry about the giant post and my inability to get it to format right. First time on this board...

We don't have the code that creates "maze" so have no idea what kind of object it is, but you should access it the same way whatever the object.
if maze[row-1,col] == 'O' or 'F': --> this doesn't make sense to me and will always be "True"
if maze(row,col) == 'F': --> this implies that maze is a function

And you should test your code as you go along instead of trying to figure out what is wrong with 100+ lines of code.

if maze[row-1,col] == 'O' or 'F': --> this doesn't make sense to me and will always be "True"

To nit pic it is allways True boolean valu first condition is True, otherwice second expression 'F' which is not a False-like value and therefore acts as True value.

Edited 4 Years Ago by pyTony

This question has already been answered. Start a new discussion instead.