Can't get a class with db to instantiate
So as you can see, in the code below, I am asking the user to log in, if not, Sign up, while saving the user's data of money, deposits, inventory in a key-value pair into the database. But to actually uses the user's stats saved to their value pair, I have to make the username available in all places in the code. Rather I assigned them to variables:
self.money = db[username] self.inventory = db[username] self.deposit_allowed = db[username] self.deposited = db[username] self.working = db[username]
But despite doing that, I get errors that "user name is not defined" and "self.inventory is not defined".
The Real Question
My real question is that how can I make the variables, that I have put up, have the values of the list that I have assigned to the value pair of the user's name and make it work globally.
Here is a portion of the important code that I am using.
class Game: def __init__(self, username): self.money = db[username] self.inventory = db[username] self.deposit_allowed = db[username] self.deposited = db[username] self.working = db[username] def database(self): enter_game = input("Do you want to  Login\n Signup:\n>") while enter_game == '1' or enter_game == '2': if enter_game == '1': username = input("Enter user name: ") password = input("Enter password: ") if username in db.keys(): if db[username] == password: print("Loggedd In") break else: print("Invalid Username, Password") break if enter_game == '2': username = input("Enter new Username: ") password = input("Enter new password: ") db[username] = [password, 300000, , 500, 0, False] break
Also, the [roject is literally massive, so rather, I have attached a link to go to the real code(The code that is used here is in the
Click here to go to the repl with the code.
Or if that doesn't work, click here:
no that is not how you use classes!
you use classes by setting the instance into something, you should never ever create a class twice like that.
game = Game(username) game.money