I'm working on a game and one of the commands, one to pickup items, is not working. The code pretty much checks to see if the item is in the room and if it is then to copy that to the players inventory and then delete the item from the room. However no matter what I try it either does nothing or copies the keys inside to the dictionary.
Here's the code:
def pickup(self, item):
conf = input('Do you want to pick up the ' + item.lower() + ': ')
if conf.lower() == 'y' or 'yes':
try:
self.inventory.update(room[self.room_number]['items'][item])
del room[self.room_number]['items'][item]
except KeyError:
print('You look everywhere but can\'t find a ' + item.lower())
else:
print('You consider it, but decide not to pick up the ' + item.lower())
When I print the inventory dictionary I get this
player.inventory
{
'type': 'weapon',
'equippable': True,
'value': 0,
'desc': 'a wooden stick, could be useful',
'name': 'Wooden Stick',
'perks': {
'defense': 0,
'health': 0,
'damage': 6,
'magic_damage': 0
}
}
or
{}
What I want is this:
player.inventory
{
'wooden stick':{
'type': 'weapon',
'equippable': True,
'value': 0,
'desc': 'a wooden stick, could be useful',
'name': 'Wooden Stick',
'perks': {
'defense': 0,
'health': 0,
'damage': 6,
'magic_damage': 0
}
}
Does anybody know how I can get this result. Nothing I try seems to work and I have checked to see whether anyone has answered this but can't find anything on it.
Thanks :)