diff demos/rpg/scripts/gamecontroller.py @ 535:9fbe3dce925a

Added custom exceptions.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 31 May 2010 18:44:48 +0000
parents 65a92a2449d5
children 1afe46247ab1
line wrap: on
line diff
--- a/demos/rpg/scripts/gamecontroller.py	Mon May 31 17:45:04 2010 +0000
+++ b/demos/rpg/scripts/gamecontroller.py	Mon May 31 18:44:48 2010 +0000
@@ -35,6 +35,7 @@
 from scripts.guicontroller import GUIController
 from scripts.actors.baseactor import TalkAction, PickUpItemAction
 from scripts.objects.baseobject import GameObjectTypes
+from scripts.misc.exceptions import ObjectNotFoundError
 
 
 class KeyState(object):
@@ -210,20 +211,22 @@
 		if cmd[0] == "spawn":
 			result = "Usage: spawn [item|actor] [id] [posx] [posy]"
 			if len(cmd) != 5:
-				print len(cmd)
 				return result
 			else:
-				if cmd[1] == "item":
-					obj = self._scene.loadItem(cmd[2])
-				elif cmd[1] == "actor":
-					obj = self._scene.loadActor(cmd[2])
-				else:
-					return result
+				try:
+					if cmd[1] == "item":
+						obj = self._scene.loadItem(cmd[2])
+					elif cmd[1] == "actor":
+						obj = self._scene.loadActor(cmd[2])
+					else:
+						return result
+				except ObjectNotFoundError, e:
+					result = "Error while loading object: " + cmd[2]
+					obj = None
+					
 				if obj:
 					self._scene.addObjectToScene(obj)
 					result = "--OK--"
-				else:
-					result = "Error: Not Found!"
 			
 		return result