vendredi 25 décembre 2020

How do I exit an if statement python

I am using the Ursina Engine to make a small game. In the game I am trying to make a menu screen. Usually I would make a function for every screen but Ursina won't allow that without losing the update function, so I am needing to improvise. I decided to use if statements instead of functions to see if it works, and it does, except this one problem.

if thing_a:
    # do code
    if key_pressed:
        # exit the previous if statement and do enable thing_a, while disabling thing_b

if thing_b:
    # do code

now the usual thing would either to be to return or make a function for breaking the if statement and moving on, however, the problem is, the keypress is inside of a class, like this:

class GamePlay:
    def __init__(self):
        game = 0
gameplay = Gameplay()
gameplay.game == 0

if gameplay.game == 0:
    class Button(Button):
        def __init__(self):
            super().__init__(
               # irrelevent stuff
        def input(self, key):
            if self.hovered:
                 if key == 'left mouse down':
                       # enable thing_b, disable thing_a <- problem is here
                       gameplay.game == 1

if gameplay.game == 1:
    # code

Upon some print() tests, I know the code is reaching there, but the problem is that I don't know how to break all of the if statements and allow for thing_b to start up. Any and all help would be appreciated, and apologies in advance for bad grammar, English is not my first language.

Aucun commentaire:

Enregistrer un commentaire