Feb-02-2019, 04:14 PM
I don't know what's going on. I don't have your full code (I don't even have Pygame), so I can't run all of it. But if I eliminate the imports I don't have, char imports and Char instantiates. You might have another variable char that is confusing things. You might have another file named char.py that is confusing things.
The way that you are importing things looks odd, and could cause other problems down the line. This is how I would recommend doing things. Have a separate file for each class, it's sub-classes, and any constants they need. None of them should have top level variables that are going to change, and none of the classes should have instances. If there is anything that two of those files need, but it into another file. Instances of the classes should only be made in other classes, or in a main program file responsible for running the overall code. These instances should be passed from class to class as attributes when needed.
For example, in my t_games project, there is a file for the Interface class. An instance of that is created in the main program file. The interface instance loads all of the game classes from their .py files, and creates an instance of the Human class from the player.py file. The interface instance creates an instance of the current game, passes the human instance to the game instance. The game instance creates instances of any AI players. These are defined in the game file, inheriting from the base classes in the player.py file. The human and the AI player instances are all passed a copy of the game instance so that they can interact with it.
The way that you are importing things looks odd, and could cause other problems down the line. This is how I would recommend doing things. Have a separate file for each class, it's sub-classes, and any constants they need. None of them should have top level variables that are going to change, and none of the classes should have instances. If there is anything that two of those files need, but it into another file. Instances of the classes should only be made in other classes, or in a main program file responsible for running the overall code. These instances should be passed from class to class as attributes when needed.
For example, in my t_games project, there is a file for the Interface class. An instance of that is created in the main program file. The interface instance loads all of the game classes from their .py files, and creates an instance of the Human class from the player.py file. The interface instance creates an instance of the current game, passes the human instance to the game instance. The game instance creates instances of any AI players. These are defined in the game file, inheriting from the base classes in the player.py file. The human and the AI player instances are all passed a copy of the game instance so that they can interact with it.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures