python - AttributeError: 'module' object has no attribute 'sleep' . My mini-game doenst Work -


here code:

    import pygame import sys import os sys import * pygame import * os import *  pygame.init()              #colour acronym chart #|  black = blck  |  grey = gry   | dark = drk    | white = wht #|  deep = dp     |  metal = mtl  | light = lht   | #|  blue = bl     |  baby = bby   | maroon = mrn  | #|  red = rd      |  fire = fr    | orange = orng |  # window colour index wht = (255, 255, 255) blck = (0, 0, 0)             dp_gry = (32, 32, 32)        mtl_gry = (96, 96, 96)     lht_gry = (160, 160, 160)  dp_bl = (0, 0, 102) lht_bby_bl = (0, 128, 255)  dark_maroon = (102, 0, 0) fire_red = (255, 0, 0) light_orange = (255, 128, 0) #end of colour module  display_width = 800 display_height = 600    gamedisplay = pygame.display.set_mode((display_width,display_height)) pygame.display.set_caption('hard drive') clock = pygame.time.clock()  carimg = pygame.image.load('car1.png') car_width = 45 car_height = 45  def car(x,y):     gamedisplay.blit(carimg,(x,y))  def text_objects(text, font):     textsurface = font.render(text, true, blck)     return textsurface, textsurface.get_rect()  def message_display(text):     largetext = pygame.font.font('freesansbold.ttf',115)     textsurf, textrect = text_objects(text, largetext)     textrect.center = ((display_width/2),(display_height/2))     gamedisplay.blit(textsurf, textrect)      pygame.display.update()      time.sleep(2)      game_loop()        def crash():     message_display('you crashed')  def game_loop():     x = (display_width * 0.45)     y = (display_height * 0.8)      x_change = 0      gameexit = false      while not gameexit:          event in pygame.event.get():             if event.type == pygame.quit:                 pygame.quit()                 quit()              if event.type == pygame.keydown:                 if event.key == pygame.k_left:                     x_change = -5                 if event.key == pygame.k_right:                     x_change = 5              if event.type == pygame.keyup:                 if event.key == pygame.k_left or event.key == pygame.k_rig ht:                     x_change = 0          x += x_change          gamedisplay.fill(wht)        car(x,y)         if x > display_width - car_width or x < 0:            crash()       pygame.display.update()     clock.tick(60)  game_loop() pygame.quit() quit() 

now here error!

python 3.2.1 (default, jul 10 2011, 21:51:15) [msc v.1500 32 bit (intel)] on win32 type "copyright", "credits" or "license()" more information. >>> ================================ restart ================================ >>>  traceback (most recent call last):   file "c:/users/*****/desktop/pygame/frame.py", line 104, in <module>     game_loop()   file "c:/users/*****/desktop/pygame/frame.py", line 98, in game_loop     crash()   file "c:/users/*****/desktop/pygame/frame.py", line 65, in crash     message_display('you crashed')   file "c:/users/*****/desktop/pygame/frame.py", line 58, in message_display     time.sleep(2) attributeerror: 'module' object has no attribute 'sleep' >>> ================================ restart ================================ >>>  

so understand im doing; im making little racing game, got error. however, before added pop-up player crashes car, ran fine, implementation of quick pop-up, crashes!

why happening. understand python, im bit lost on part.

you need import module time fix error 'module' object has no attribute 'sleep'.
try writing import time on first line.
or
remove line time.sleep(2), don't need it.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -