Problem with updating score in pygame – including a for loop

Could anyone help me fix my score system?
I am coding a game where the user is shown a clock face and needs to choose the correct time from three options (answer1, answer2 and answer3). Once they have chosen their answer, if they are correct, the variable user_score should increment by one, and if they are incorrect the variable wolf_score should increment by one.
The variables are defined outside of the while loop initially as zero, there is a for loop in which the event for mouse button down is checked and the variables increase, and the text displayed on screen is defined after the loop.
The score should update once the user choses their answer, but it does not change when the code is run, it stays at 0.
This is my first post, so sorry if I have not given enough details, of if the code is hard to follow!

I have tried moving the code around, defining the variables in different ways and using global variables with no success…. I don’t know if I’ve been staring at the code for too long but I just can’t seem to work out where I’ve gone wrong, so any help is greatly appreciated.

I have attached below my code to analyse as you need:

def clocks():
      #define variables
       running= True
       answer= None
       user_score = 0
       wolf_score = 0
       
       while running : #game loop 

            #get mouse pos
            CLOCKS_MOUSE_POS = pygame.mouse.get_pos()

            #drawing
            GAME_TEXT= font.render("Let's play!", True, "white")
            GAME_RECT= GAME_TEXT.get_rect(center= (500,100))
            screen.blit(GAME_TEXT, GAME_RECT)    

            #generate correct answer
            answer1= Answer(None, (500, 590), question.getAnswer(), font, "Red", "Dark Red" , "")
            answer1.changeColor(CLOCKS_MOUSE_POS)
            answer1.update(screen)


            #pygame.display.flip()
            pygame.display.update()
    

        #gameloop events
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    exit()
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if answer1.checkForInput(CLOCKS_MOUSE_POS):
                        buttonclick_sound.play()
                        user_score += 1
                        correct() 
                        pygame.display.update()
                      
                    if answer2.checkForInput(CLOCKS_MOUSE_POS):
                        buttonclick_sound.play()
                        wolf_score += 1
                        incorrect()
                        pygame.display.update()
                      
                    if answer3.checkForInput(CLOCKS_MOUSE_POS):
                        buttonclick_sound.play()
                        wolf_score += 1
                        incorrect()
                        pygame.display.update()
                    
                       
                    if pausebutton.checkForInput(CLOCKS_MOUSE_POS):
                        buttonclick_sound.play()
                        pause()

                    if backbutton.checkForInput(CLOCKS_MOUSE_POS):
                        buttonclick_sound.play()
                        play()
                    #pygame.display.flip()
            user_score_text = font.render(f"{user_score}", True, "Yellow")
            screen.blit(user_score_text, (20, 100)) 

            wolf_score_text = font.render(f"{wolf_score}", True, "Yellow")
            screen.blit(wolf_score_text, (920, 100)) 


            pygame.display.update()
 


New contributor

Jemima Hilton is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật