Should I have everything in one script or should I have more scripts and connect them?

Question:

I’m making a game and I don’t know if I should have the whole game in one script or the script for the main menu alone and for the options menu alone and the for the actual gameplay alone… and connect them. So, what is the better option and if I should make more scripts how can I connect them? Is it making a manager script and making other scripts functions and the calling the from the manager sript? Or should I make whole other scripts classes?

Asked By: Mirko Dolenc

||

Answers:

If you have separate files for each class, (my opinion by the way, it generally depends on you) it would be much easier to manage your different classes, especially without having to scroll through one giant file. Also fun fact, this is known as modular programming

Of course, sometimes it may be too complex to relocate all your code to multiple files, or there may be other restrictions preventing you from doing so, and in this scenario, you probably wouldn’t separate your code into multiple scripts.

Now about making other scripts classes, that would entirely depend on their usage. If you had an interactive menu, or perhaps an interactive object (such as a player or enemy) it would probably be better as a class then a series of functions.

But to connect them, with Python, you can easily import the classes based on their files with import fileName. (of course replace fileName with your file’s name, and path) You can read more about importing different classes here

Answered By: realhuman
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.