Reputation:
I am making a "fan game" of Five Nights at Freddy's. My code was working fine until I started getting this error:
File "C:\Users\Admin\Desktop\Python\Five Nights\Five Nights.py", line 116, in main
clock.tick(40)
AttributeError: 'function' object has no attribute 'tick'
I have compared the code to other working pygame games and the code for the clock is exactly the same, but I only get this error in this game.
My code is as follows:
import pygame, random
pygame.init()
screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN, 32)
pygame.display.toggle_fullscreen()
pygame.display.set_caption("Five Nights")
clock = pygame.time.Clock()
office_pic = pygame.image.load('images/office.png')
stage = pygame.image.load('images/stage.jpg')
building_map = pygame.image.load('images/map.png')
building_map.convert_alpha()
breathing = pygame.mixer.Sound('sounds/breathing.wav')
screen_width = 1280
screen_height = 800
x = 0
x_move = 0
v = 0
camera = stage
camera_up = False
click = None
fps_tick = 0
seconds = 0
hour = 10
def clock():
global fps_tick, seconds, hou
fps_tick += 1
if fps_tick == 40:
seconds += 1
fps_tick = 0
if seconds == 30:
hour += 1
def cameras(mouse_x, mouse_y):
global click, camera
screen.blit(camera, (0,0))
screen.blit(building_map, (screen_width-650, screen_height-426))
def main():
global x, x_move, camera_up, v, click
while True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
quit()
mouse_xy = pygame.mouse.get_pos()
mouse_x = mouse_xy[0]
mouse_y = mouse_xy[1]
click = pygame.mouse.get_pressed()
if mouse_x >= (screen_width/2) + 200 and mouse_x <= (screen_width/2) + 400:
x_move = 5
elif mouse_x <= (screen_width/2) - 200 and mouse_x >= (screen_width/2) - 400:
x_move = -5
elif mouse_x > (screen_width/2) + 400:
x_move = 10
elif mouse_x < (screen_width/2) - 400:
x_move = -10
else:
x_move = 0
x -= x_move
if mouse_y >= (screen_height - (screen_height / 6)) and camera_up == False and v == 0:
camera_up = True
if not mouse_y >= (screen_height - (screen_height / 6)) and camera_up == True:
v = 1
if mouse_y >= (screen_height - (screen_height / 6)) and camera_up == True and v == 1:
screen.fill((0,0,0))
camera_up = False
if not mouse_y >= (screen_height - (screen_height / 6)) and camera_up == False:
v = 0
if camera_up == False:
screen.blit(office_pic, (x,0))
if camera_up == True:
cameras(mouse_x, mouse_y)
pygame.display.update()
clock.tick(40)
main()
Upvotes: 2
Views: 2168
Reputation: 6160
You overwrote the clock = pygame.time.Clock()
class at the top of the file with a function also called clock.
def clock():
global fps_tick, seconds, hou
fps_tick += 1
if fps_tick == 40:
seconds += 1
fps_tick = 0
if seconds == 30:
hour += 1
Upvotes: 0
Reputation: 90949
You have a function named clock()
-
def clock():
global fps_tick, seconds, hou
fps_tick += 1
if fps_tick == 40:
seconds += 1
fps_tick = 0
if seconds == 30:
hour += 1
Which is masking the clock = pygame.time.Clock()
variable, hence when you access clock
name, it accesses the function you have created.
I do not see you using the function anywhere, if its actually in use in some part of code that you have not posted, you should rename it such that the name does not mask other variables you have created. If you are not using the function, remove it.
Upvotes: 2