Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Room lets you use exit as a direction even though it is a method #43

Open
coco7nut001 opened this issue Jan 15, 2022 · 8 comments · May be fixed by #47
Open

Room lets you use exit as a direction even though it is a method #43

coco7nut001 opened this issue Jan 15, 2022 · 8 comments · May be fixed by #47

Comments

@coco7nut001
Copy link

Whenever I do 'north', 'east', 'west' or 'south', the game crashes with an error:

Traceback (most recent call last):
  File "C:\Users\84367\Desktop\main.py", line 81, in <module>
    start()
  File "G:\Python\lib\site-packages\adventurelib.py", line 536, in start
    _handle_command(cmd)
  File "G:\Python\lib\site-packages\adventurelib.py", line 509, in _handle_command
    func(**args)
  File "C:\Users\84367\Desktop\main.py", line 53, in go
    room = current_room.exit(direction)
TypeError: 'NoneType' object is not callable
@coco7nut001
Copy link
Author

I'm using Python 3.10.1 Not sure if that helps

@lordmauve
Copy link
Owner

Please can you provide a minimal reproducible example?

@coco7nut001
Copy link
Author

Please can you provide a minimal reproducible example?
Oh it return error when I go in a customized direction like up-down

@coco7nut001
Copy link
Author

from adventurelib import *
Room.add_direction('up', 'down')
Room.add_direction('enter', 'exit')

@when('north', direction='north')
@when('south', direction='south')
@when('east', direction='east')
@when('west', direction='west')
def go(direction):
    global current_room
    room = current_room.exit(direction)
    if room:
        current_room = room
        print(f'You go {direction}.')
        look()
tent = Room(...)
camp = Room(...)
river = Room(...)
camp.enter = tent
camp.down = river

@lordmauve
Copy link
Owner

The problem is that you are using exit as a direction, when it is also used as a method to get an exit. I think adventurelib should stop you using directions that conflict with methods in the Room class.

@lordmauve lordmauve changed the title Moving between rooms return a NoneType error. Room let's you use exit as a direction even though it is a method Jan 16, 2022
@lordmauve lordmauve changed the title Room let's you use exit as a direction even though it is a method Room lets you use exit as a direction even though it is a method Jan 16, 2022
@coco7nut001
Copy link
Author

Is there any way to get around that annoying thing?

@lordmauve
Copy link
Owner

Yes:

  • Don't use enter/exit as your directions, use enter/out for example
  • Bind the command exit to the direction name you use, so out if that's what you go with:
    @when('exit', direction='out')

@Vaporbook
Copy link

I got snagged on this too ... turns out I had done a copypasta from the docs, so you might want to change this line: https://github.com/lordmauve/adventurelib/blob/master/doc/rooms.rst?plain=1#L209 ...

I'm grateful for this very cool library - having a lot of fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants