'List'对象没有属性'update'

时间:2015-02-11 03:46:37

标签: python list updates scite

我是使用Python SciTE的新成员和新手程序员。我有一个项目,我必须制作一个游戏,包括让一个动画人物的时间做跳跃,并且我试图运行它,只是为了表明我的列表对象没有&#39 ;更新'在引擎功能。我有一长串代码。我试图弄清楚问题是什么。

计时器类:

def __init__(self,position,start_value,size = 20,color = gc.WHITE,font = "Arial"):
    ''' Initializes the timer.
        Start value is in seconds. '''
    self.original_time = start_value    

    self.time = start_value

    self.max = start_value * 1000

    self.x = position[0]
    self.y = position[1]

    self.size = size
    self.color = color
    self.font = font

    self.active = False

    pass

def is_active(self):
    """ Tells the program if the timer is on. """

    return self.active

def get_value(self):
    """ Tells the program the current value of the timer. """
    return self.time

def start(self,time = None):
    """ Starts the timer. """
    self.active = False
    self.time = self.original_time

    pass

def update(self,time):
    """ Iterates the value of the timer.
        deactivate returns True if the timer reaches zero. """

    deactivate = False
    if self.active:
        #
        # Iterate time
        #

        self.time -= time

        #
        # Deactivate the timer when the countdown finishes.
        #
        if self.time <= 0:
            self.stop()
            dreactivate = True


    return deactivate

def draw(self,screen):
    """ Prints the value of the timer to the screen. """

    output = format_time(self.time)
    position = [self.x, self.y]

    #
    # Print the output string
    #
    gc.screenprint(screen,outpit,position)

发动机:

#
# MVC FUNCTIONS
#

def engine(interval,avatar,timer):
''' The engine models the physics of your game by updating object
positions, checking for collisions, and resolving them. '''

    score = False

    if avatar != None:
        score = avatar.update(interval)
        timer.update(interval)

return score

回溯:

Traceback (most recent call last):
  File "jumpingjacks_template(1).py", line 458, in <module>
    main()
  File "jumpingjacks_template(1).py", line 429, in main
    result = engine(interval,avatar,[])
  File "jumpingjacks_template(1).py", line 316, in engine
    timer.update(interval)
AttributeError: 'list' object has no attribute 'update'

1 个答案:

答案 0 :(得分:0)

Traceback (most recent call last):
  File "jumpingjacks_template(1).py", line 458, in <module>
    main()

Traceback的这一部分显示您正在使用第三个参数(enigine), - timer的空列表调用def engine(interval,avatar,timer)

  File "jumpingjacks_template(1).py", line 429, in main
    result = engine(interval,avatar,[])

然后功能代码调用等同于timer.update的{​​{1}},因此它会抛出[].update

AttributeError

您需要查看第429行,找出您为第三个参数使用列表的原因。