Open coco7nut001 opened 2 years ago
I'm using Python 3.10.1 Not sure if that helps
Please can you provide a minimal reproducible example?
Please can you provide a minimal reproducible example? Oh it return error when I go in a customized direction like up-down
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
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.
Is there any way to get around that annoying thing?
Yes:
enter
/exit
as your directions, use enter
/out
for exampleexit
to the direction name you use, so out
if that's what you go with:
@when('exit', direction='out')
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!
Whenever I do 'north', 'east', 'west' or 'south', the game crashes with an error: