-4

So I have this code

score = 0

def on_button_pressed_a():
    score = score + 1
    print(score)
input.on_button_pressed(Button.A, on_button_pressed_a)

And I know that the problem is the score = 0 being outside the subroutine. However if I put score = 0 into the subroutine whenever the button is pressed it will always return to 0. How can i fix this (I cant use classes btw)

Michael Butscher
  • 10,028
  • 4
  • 24
  • 25

1 Answers1

2

Maybe try putting global score at the start of on_button_pressed_a?

Solomon Ucko
  • 5,724
  • 3
  • 24
  • 45