python - TypeError: tuple indices must be integers

Verstehe ich nicht, was falsch ist. Ich poste den Teil des Codes, relevant ist.

Fehler:

Traceback (most recent call last):
  File "C:\Python\pygame\hygy.py", line 104, in <module>
    check_action()
  File "C:\Python\pygame\hygy.py", line 71, in check_action
    check_portal()
  File "C:\Python\pygame\hygy.py", line 75, in check_portal
    if [actor.x - 16, actor.y - 16] > portal[i][0] and [actor.x + 16, actor.y + 16] < portal[i][0]:
TypeError: tuple indices must be integers

Funktion:

def check_portal():
    for i in portal:
        if [actor.x - 16, actor.y - 16] > portal[i][0] and [actor.x + 16, actor.y + 16] < portal[i][0]:
            if in_portal == False:
                actor.x,actor.y=portal[i][1]
                in_portal = True
        elif [actor.x - 16, actor.y - 16] > portal[i][1] and [actor.x + 16, actor.y + 16] < portal[i][1]:
            if in_portal == False:
                actor.x,actor.y=portal[i][1]
                in_portal = True
        else:
            in_portal = False

initialisieren Schauspieler:

class xy:
  def __init__(self):
    self.x = 0
    self.y = 0
actor = xy()

initialisieren portal:

portal = [[100,100],[200,200]],[[300,300],[200,100]]

InformationsquelleAutor kommihe | 2012-03-05

Schreibe einen Kommentar