add more try/except. Also handle new method of parenting room names

This commit is contained in:
Joe S 2021-02-26 21:45:58 -05:00
parent 3aa6d426fe
commit bcb2ee060d
1 changed files with 11 additions and 10 deletions

View File

@ -46,8 +46,7 @@ class Handler(npyscreen.ButtonPress):
player = self.parent.parentApp.player player = self.parent.parentApp.player
roomlocation = player.playerData['player']['location'] + '.yaml' roomlocation = player.playerData['player']['location'] + '.yaml'
try: try:
room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)[ room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room']
player.playerData['player']['location']]
# If the file could not be found # If the file could not be found
except FileNotFoundError: except FileNotFoundError:
@ -102,14 +101,16 @@ class Handler(npyscreen.ButtonPress):
self.parent.update_log("You must specify something to pick up.") self.parent.update_log("You must specify something to pick up.")
elif command == 'OPEN': elif command == 'OPEN':
try: #try:
self.parent.parentApp.log.info('Player tried to open door: {0}'.format(arguments[0])) self.parent.parentApp.log.info('Player tried to open door: {0}'.format(arguments[0]))
new_room = room[arguments[0].lower()]['leads_to'] new_room = room[arguments[0].lower()]['leads_to']
self.parent.parentApp.log.debug('New room is: {0}'.format(new_room)) self.parent.parentApp.log.debug('New room is: {0}'.format(new_room))
except KeyError: upon_enter = player.change_room(new_room) # Change the player to that new room.
self.parent.update_log("You cant open that.") self.parent.update_log(upon_enter) # Print the new room upon enter text.
except IndexError: #except KeyError:
self.parent.update_log("you must specify something to open") # self.parent.update_log("You cant open that.")
#except IndexError:
# self.parent.update_log("you must specify something to open")
else: else:
self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command)) self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command))