comparison 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
comparison
equal deleted inserted replaced
530:ea26e7b6f56c 531:801746c5bb9a
199 """ 199 """
200 200
201 result = "" 201 result = ""
202 202
203 args = command.split(" ") 203 args = command.split(" ")
204 cmd = []
204 for arg in args: 205 for arg in args:
205 arg = arg.strip() 206 arg = arg.strip()
206 207 if arg != "":
207 if args[0] == "spawn": 208 cmd.append(arg)
208 if len(args) != 4: 209
209 result = "Usage: spawn [itemid] [posx] [posy]" 210
211 if cmd[0] == "spawn":
212 result = "Usage: spawn [item|actor] [id] [posx] [posy]"
213 if len(cmd) != 5:
214 print len(cmd)
215 return result
210 else: 216 else:
211 result = "Success!" 217 if cmd[1] == "item":
218 obj = self._scene.loadItem(cmd[2])
219 elif cmd[1] == "actor":
220 obj = self._scene.loadActor(cmd[2])
221 else:
222 return result
223 if obj:
224 self._scene.addObjectToScene(obj)
225 result = "Success!"
226 else:
227 result = "Error: Not Found!"
212 228
213 return result 229 return result
214 230
215 def newGame(self): 231 def newGame(self):
216 self._guicontroller.hideMainMenu() 232 self._guicontroller.hideMainMenu()