RE: Python (Trouble with Aliens!)

  • From: Rodney Haynie <RodneyH@xxxxxxxxxx>
  • To: "programmingblind@xxxxxxxxxxxxx" <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 17 Apr 2009 08:06:17 -0400

When you iterate through your collection of Aliens, I will be an alien.  So 
treat it like one.

Instead of
aliens[i].move()

You would use:
i.move()
if i.getxpos() == x:


HTH.
-Rodney




Please consider the environment before printing this email.

From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of BlueScale
Sent: Friday, April 17, 2009 7:17 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Python (Trouble with Aliens!)

Hi,
I am having some trouble with my aliens.  Here's the code:
for i in aliens:
  aliens[i].move()
  if aliens[i].getxpos() == x:
   lockOn.play()
The error I am getting is:
TypeError: object cannot be interpreted as an index
Can someone please help me make my aliens behave better?
Thanks

Other related posts: