Comparing coordinates not working

Comparing coordinates not working

Postby jedi_mind_ » Wed Jun 25, 2014 11:03 pm

Code: Select all
def scanRects(Rects):
   for J in range(len(Rects)):
      if Rect[J].topleft[0] < 750 and Rect[J].topleft[1] < 550:
         moveRects(Rect=Rect[J])


line 3 the if statement
TypeError: 'type' object has no attribute '__getitem__'
jedi_mind_
 
Posts: 11
Joined: Sun Jun 08, 2014 5:31 pm

Re: Comparing coordinates not working

Postby Mekire » Wed Jun 25, 2014 11:44 pm

Mind explaining what it is you actually want to do?
Then provide enough code so we can actually test it.

As to your current code:
  • Don't capitalize variables unless they are classes (not instances; actual class types).
  • Itterate through the sequence; not range(len(sequence)):
    Code: Select all
    def scan_rects(rects):
       for rect in rects:
          if rect.top < 750 and rect.left < 550:
             move_rects(rect)
  • You can probably just use rect collision functions for this rather than writing your own function. I would need to see more context.
  • Don't use * imports. You haven't shown it here, but I almost guarantee you are using "from pygame.locals import *".
    Rect is a class in pygame, you meant to write Rects[J], but for the previously stated reasons, don't do this either.

-Mek
User avatar
Mekire
 
Posts: 1033
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Comparing coordinates not working

Postby jedi_mind_ » Sat Jun 28, 2014 12:57 am

thanks I start implementing those style conventions today.
jedi_mind_
 
Posts: 11
Joined: Sun Jun 08, 2014 5:31 pm


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests