TacoCat
TacoCat

Reputation: 469

Function isn't working without showing errors - python

I'm building a game "Alien Invasion" from the book "Python crash course". (maybe someone has done the same).

At this point I'm trying to get my "PLAY" button working, everything is showing and I'm not getting any errors, but when I click the button nothing happens, game is not running because the game_active remains FALSE.

--Main call--

 gf.check_events(ai_settings, screen, stats, play_button, ship, bullets)

--Check events function--

def check_events(ai_settings, screen, stats, play_button, ship, bullets):
    """Respond to keypresses and mouse events."""
    for event in pygame.event.get():

        *snipped because not relevant*

        elif event.type == pygame.MOUSEBUTTONDOWN:
            mouse_x, mouse_y = pygame.mouse.get_pos()
            check_play_button(stats, play_button, mouse_x, mouse_y)

--Check_play_button function--

def check_play_button(stats, play_button, mouse_x, mouse_y):
    """Start a new game when the player presses play"""
    if play_button.rect.collidepoint(mouse_x, mouse_y):
        stats.game_active == True

I think everything is imported correctly and if it wasn't then I would be getting an error. This is the code that is responsible for the click event.

If I haven't provided something let me know.

Upvotes: 2

Views: 219

Answers (1)

japhyr
japhyr

Reputation: 1780

In the last line of check_play_button() you have a conditional test. Replace == with =, and see if that works.

Right now the code is checking whether stats.game_active is True; you want it to set stats.game_active to True.

Upvotes: 1

Related Questions