vendredi 25 décembre 2020

How do I get an if statement to run after a variable has changed?

Here is an example as to what I am doing:

class Something():
    def __init__(self):
        self.game = 0

something = Something()

if something.game == 0:
    # code is here
    if something happens:
        something.game = 1

if something.game == 1:
    # code is here

The problem is when something.game switches to 1, the second if statement doesn't run. I've switched the "if something.game == 1:" to elif but that isn't working either. I used a class system to avoid having to use global variables, but I have tried using global variables and it also didn't work.

Edit: The problem is the if something happens: something.game = 1 part. something.game turns into a 1 (I think), but it won't do the other part of the code (the other part of the code meaning the second if statement: "if something.game == 1:")

Aucun commentaire:

Enregistrer un commentaire