2

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.