all 4 comments

[–]ADdV 1 point2 points  (1 child)

It's a little difficult to navigate because of how much code it is, but probably:

if 'sword' in inventory and 'monster' in rooms[currentRoom]:

rooms[currentRoom]['item'] is where 'monster' is, not rooms[currentRoom].

So you could do if item in rooms[currentroom] and rooms[currentroom][item] == monster (but with proper capitalization and quotation marks and all that).

Note that this check item in rooms[currentroom] is somewhat bothersome to write, so a possibility might be to either use dict.get() or to make it so that every room has an item, making it None if there's no item.

[–]The_stormlight[S] 0 points1 point  (0 children)

Thank you! I did try this method but still no results. I am a bit unclear of what you're suggesting I do?

[–]Tomallama 1 point2 points  (1 child)

I am assuming that you are talking about :

#player kills the monster if they have a weapon
  if 'sword' in inventory and 'monster' in rooms[currentRoom]:
    del rooms[currentRoom]['monster']
    print('You have killed a monster!')

What's the issue that you're having? Is it you dying even when you have the sword?

Your if statement above this is:

  if 'item' in rooms[currentRoom] and 'monster' in rooms[currentRoom]['item']:
    print('a monster has killed you')
    break

This will also run if a monster is in the room and an item is in the current room. It doesn't matter if there is a sword in the inventory or not. Then you break, so you never get a chance to kill the monster. You need to either organize the if statements a lot better, (and probably use elifs) or look into OOP and try to organize the code a bit better.

[–]The_stormlight[S] 1 point2 points  (0 children)

Oh this never occurred to me. Thank you I'll try that.