lordmauve / adventurelib

A minimal library for writing text adventure games in Python 3
https://adventurelib.readthedocs.io/
MIT License
153 stars 42 forks source link

Inventory.find problem #34

Open pango47 opened 4 years ago

pango47 commented 4 years ago

testadventurelib.py I edited the cast(magic) function by adding

    obj = inventory.find('mallet')
    drop(obj)

as shown below.

def cast(magic): if magic == None: say("Which magic you would like to spell?") elif magic == 'fireball': say("A flaming Fireball shoots form your hands!") obj = inventory.find('mallet') drop(obj)

This produces the error:

cast fireball A flaming Fireball shoots form your hands! Traceback (most recent call last): File "main.py", line 85, in start() File "/opt/virtualenvs/python3/lib/python3.8/site-packages/adventurelib.py", line 536, in start _handle_command(cmd) File "/opt/virtualenvs/python3/lib/python3.8/site-packages/adventurelib.py", line 509, in _handle_command func(**args) File "main.py", line 82, in cast drop(obj) File "main.py", line 52, in drop obj = inventory.take(thing) File "/opt/virtualenvs/python3/lib/python3.8/site-packages/adventurelib.py", line 260, in take obj = self.find(name) File "/opt/virtualenvs/python3/lib/python3.8/site-packages/adventurelib.py", line 236, in find if name.lower() in item.aliases: AttributeError: 'Item' object has no attribute 'lower'

if I change obj in drop(obj) to drop('mallet') it functions as expected.

yonderbread commented 4 years ago

Bag.find takes a string as it's argument, not a object. You're getting this error because .lower() is a method for strings only.