2 Replies - 503 Views - Last Post: 20 May 2012 - 06:58 PM Rate Topic: -----

#1 MINICOMIXX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-May 12

Invalid Indentation?

Posted 20 May 2012 - 11:51 AM

Whenever I try to run the program it says line 59 has invalid indentation. I have tried many things including tabifying the area and untabifying the area, I have also tried to rewrite the line.

class Player(object):
	def __init__(self):
		self.keys = 0
		self.isDone = False
		self.startRoom = StartRoom()
		self.bathRoom = BathRoom()
		self.currentRoom = self.startRoom
		self.started = False
	def play(self):
		while not self.isDone:
			print "Current keys =", self.keys	
			print "Type 'Help' for a full list of commands."
			cmd = raw_input("Type a command:")
			if cmd == "Help":
				print "Look, Examine (Object), N,W,E,S, Take (Item), Remember to Capitalize all Words!"
				self.currentRoom.process(self, cmd)

class StartRoom(object):
	def __init__(self):
		self.chestkeys = 1
		self.foundkeys = False
	def display(self, player):
		if not player.started:
			print'''You wake up in your room in the castle. As you look around it seems as though it has
		been ransacked. Your chest is open and so is your dresser.
		You notice a slight breeze and see that the window has been smashed too!'''
			player.started = True
		print "You are in your room. The window is smashed and the room is ransacked, the exits are (W)est and (N)orth."
	def process(self, player, cmd):
		if cmd == "W":
			player.currentRoom = player.bathRoom
		elif cmd == "Examine Window":
			print "OUCH! I wouldn't go over there with all that broken glass!"
		elif cmd == "Examine Chest":
			if self.chestkeys==0:
				print "It's empty now"
				print "You see", self.chestkeys, "Key(s) in the Chest! Type 'Take Key' to take it!"
				self.foundkeys = True
		elif cmd == "Take Key":
			if self.chestkeys==0 or not self.foundkeys:
				print "I don't see any keys here."
				print "You get", self.chestkeys, "Key(s)!"
				player.keys += self.chestkeys
				self.chestkeys = 0

		elif cmd == "N":
                        if player.keys >= 2:
                                print "Coming soon"
                                print "You need more KEYS"
		elif cmd == "Examine Dresser":
			print "The dresser has been ransacked and all your clothes have fallen out, there is nothing of importance here"


class BathRoom(object):
	def __init__(self):
		self.keys = 1
		self.foundkeys = True

	def display(self, player):
		print "You are in your ensuite bathroom, It looks like not much has been touched, you see that there is a crack in the medicine cabinet. The chamberpot sits in one corner. The only exit is the the (E)ast, the way you came."

	def process(self, player, cmd):
		if cmd == "E":
			player.currentRoom = player.startRoom
		elif cmd == "Examine Chamberpot":
			print "You lift the lid off the top and find", self.keys, "Key(s)! Type 'Take Key' to get it!"
		elif cmd == "Take Key":
			if self.keys==0 or not self.foundkeys:
				print "I don't see any key(s) here."
				print "You found", self.keys, "Key(s) in the chamberpot!"
				player.keys += self.keys
				self.keys= 0
		elif cmd == "Examine Medicine Cabinet":
			print "You find nothing missing but there is nothing of use here"


Is This A Good Question/Topic? 0
  • +

Replies To: Invalid Indentation?

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 756
  • View blog
  • Posts: 1,990
  • Joined: 23-December 08

Re: Invalid Indentation?

Posted 20 May 2012 - 12:52 PM

As I'm sure you know, indentation is very important in Python.

Well, consistency in indentation is equally important. As a rule, every indent should be 4 spacess. Look at how many spaces are between the indentation of line 58 and 59, that's way more than 53 and 54.
Was This Post Helpful? 1
  • +
  • -

#3 x68zeppelin80x  Icon User is offline

  • D.I.C Addict

Reputation: 105
  • View blog
  • Posts: 509
  • Joined: 07-March 09

Re: Invalid Indentation?

Posted 20 May 2012 - 06:58 PM

Myths About Indentation
You should check this out, very helpful.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1