diff demos/rpg/scripts/gamecontroller.py @ 531:801746c5bb9a

Added the spawn console command. Introduced some exception handling when loading items and objects. Will have to do more of this as the project progresses.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 28 May 2010 21:47:59 +0000
parents ea26e7b6f56c
children 65a92a2449d5
line wrap: on
line diff
--- a/demos/rpg/scripts/gamecontroller.py	Fri May 28 20:10:33 2010 +0000
+++ b/demos/rpg/scripts/gamecontroller.py	Fri May 28 21:47:59 2010 +0000
@@ -201,14 +201,30 @@
 		result = ""
 		
 		args = command.split(" ")
+		cmd = []
 		for arg in args:
 			arg = arg.strip()
+			if arg != "":
+				cmd.append(arg)
+		
 	
-		if args[0] == "spawn":
-			if len(args) != 4:
-				result = "Usage: spawn [itemid] [posx] [posy]"
+		if cmd[0] == "spawn":
+			result = "Usage: spawn [item|actor] [id] [posx] [posy]"
+			if len(cmd) != 5:
+				print len(cmd)
+				return result
 			else:
-				result = "Success!"
+				if cmd[1] == "item":
+					obj = self._scene.loadItem(cmd[2])
+				elif cmd[1] == "actor":
+					obj = self._scene.loadActor(cmd[2])
+				else:
+					return result
+				if obj:
+					self._scene.addObjectToScene(obj)
+					result = "Success!"
+				else:
+					result = "Error: Not Found!"
 			
 		return result