I'm using python and I'm making a game, but there's one thing I don't get.
Why does this boolean reset? I don't want boolean 'powerup' to reset.
def spawnPowerup()
number = 0
powerup = False
if (a certain thing happens, the thing happens for one frame.):
number = random.randint(1,2)
if number == 1 or powerup == True:
print(powerup)
powerup = True
print(powerup)
The idea behind this code is, whenever the thing happens, I get a number. When the number is equal to 1, the powerup should be activated, but since the number in changing the whole time I need this boolean. So whenever the number is equal to 1 I change the boolean falue, so the if statement will always be true when the number has been equal to 1. But the problem is that the boolean resets. If the thing happens a couple of times this will be printed:
False
True
False
True
False
True
False
True