Running the entire game on 2 scripts. Good or bad idea?

Is it a good idea to run an entire game with 2 scripts and some modules? Will it make things messy or it’s a good way to manage development?

Code structure:
CodeStructureOfMyGame

I only used a few module scripts because they’re not needed that much.

10 Likes

It’s not going to affect performance at all, but it’s definitely going to make organising your code far more difficult.
It will seem easier in the beginning, but once you get to a couple thousands lines of code you’re going to begin regretting it.

6 Likes

I’m already at the point of thousands of lines. It feels easier to manage instead of having like a million scripts all over the entire DataModel.

1 Like

If you’re fine with it, then roll with it. It’s completely your choice. It may make it difficult for others who are working with you to edit the scripts though.

7 Likes

True, they’re going to have one heck of a time.

1 Like

I personally use 2 main scripts and a handful of modulescripts. The Main Client Script and Main Server Script, and then a ModuleScript for all the miscellaneous functions that both client and server use as well as a bunch of asset libraries.

4 Likes

As will you if you have to take a month break

6 Likes

When I started off I used to put scripts everywhere, then I did a 3 script architecture using last leaders (1 in StarterPlayer, 1 in ReplicatedFirst, 1 in ServerScriptStorage) but felt limited and often frustrated by trying to be strict with this system so now I do a sort of hybrid. I use modules for object orientated programming interfaces and have most of my main code in around 10 scripts throughout ReplicatedFirst, ServerScriptStorage, and StarterPlayerScripts. If you find this method best then go for it but I don’t think it is. 2/3 main scripts can get messy very fast especially if lots of game mechanics are tun within them - not just the loading and running of modules.

1 Like

Using a single Server handler and a singke Client handler is good as long as your modules are clear in what they are doing

How I do it treat every module as an object with an init and tick function, and every run service tick, parse the time between frames to a ‘tick’ function

1 Like

2 scripts can totally run the game and it isn’t bad, but if your gonna have a lot of lines it would be best to arrange them by using – on top of each and next to — you write what it does, but anyway good luck with your game.

1 Like

The correct answer to this: there is no correct single answer.
Many of the answers you receive are / will be mostly opinionated and can be correct because we all learn differently and at different paces. Some people like having two “main” scripts in the entire game, that depend on several module scripts. One main script for the server, and one main script for the client, each with a lot of modules.

Others like to have many scripts, some like to have both!

The choice is actually yours. Just keep in mind that it’s YOU, and possibly OTHERS that will continue to work on the codebase you made now, in the future (if you continue on the project, :wink: ) This means that you need to always prioritize readability, scalability, and maintainability so that everyone including yourself can understand what you tried to do 3 months ago.

I know this might sound hard, or impossible, but try to imagine 3 months into the future. You are to add a huge update to your game. Then, since you haven’t touched the game since before those 3 months, you have completely forgotten about the structure in your game. Would you then be able to properly “catch up” to the point where you were before you “quit”? If you struggle with this, surely you must have an old project that you abandoned some time ago. Edit it and pretend like you’re going to continue working on it.

If you didn’t properly structure your game then, you can see how hard it actually is to remember what you were doing back then, and how in the world you are supposed to continue on that.


Back to opinions…

I prefer to use several server scripts and local scripts. But, each and everyone has their own purpose in the game. For example, I want to have one script with its dependencies that handle all the saving in the game, one that does the rounds (voting, loading, etc.), one that deals with player input, etc. etc.

I would say it doesn’t matter, as long as you’re not creating 100s of scripts spread anywhere and everywhere in the game so it’s not maintainable. Keep your scripts separate from everything else.

Think about a pocket, like a pocket in your jacket or anything. If you put everything into the same pocket, how hard would it be to find your card, some chewing gum, or some coins when you needed them? It would take more time, and you would possibly even have to look in your own pocket (like an idiot) as well to make sure you actually pick the correct thing. The point? You waste time and you look like a noob (no offense, noobs :frowning: ).

This is a bad example, yes, but I like to put things into different angles and perspectives so I can get a better view on it. Now, what if I kept the money in one pocket, and the other stuff that I don’t need to handle that often, in another pocket. I find what I need in one second and I don’t look like an idiot anymore! (mission accomplished :sunglasses:)

20 Likes

I personally wouldn’t do this as it’ll be extremely hard to maintain long term.

1 Like

Reading code to writing code is roughly 10:1

for a small game I’d think this would be ok to do, but it will get harder and harder the larger the game becomes

multiple scripts be helpful when you’re reading/debugging code because there is less code clutter, if there is a bug with matchmaking you can go to the matchmaking script etc

this helps me a lot because I swear my bugs are often so dumb and easily overlooked and that would happen more often if I did everything in one script

just my own take on it

It’s up to you. However I rather make many scripts in ServerScriptService. It’s not bad to use ModuleScripts. For example you have DiscordLog as ModuleScript and that’s good idea because I might contain some functions you wish to use a lot in many situations. And for the client side I would implement the main game functionality in server and use ReplicatedStorage & RemoteEvents and make few LocalScripts in StarterPlayerScripts to get client side working. I would also put a LocalScript in StarterGui or PlayerGui of the player to handle Gui (like button clicks).

I made my LocalScript “Client” and put in in ServerStorage.ClientScripts folder and disabled it. Then I implemented a script in ServerScriptService that checks when player joins and then copies the client LocalScript to the player and then enables it

This is how AeroGameFramework operates, with one script for the server and one script for the client. Everything is tucked away into neat little module scripts therafter.

I’m using it for my own project, and I don’t see any issue.
image

Then why do you have 44 local scripts? That’s an average of 53 lines of code per script. Doesn’t sound like a very organised setup to me.

30 are for GUI particle emitters, which are packages, and the remainder are forked core scripts.

Why can’t you just use one script?

I see this is already answered but I figured I’d give my feed back anyways!

As a developer who uses the same methods, I can actually say that this is a very good method in many ways than some may think.

You see, some like to just connect modules and require them accordingly, however there’s a way I prefer to do it

But skipping passed if it is a good idea, I would like to give a decent structure example of how I do my work in studio.

Alright, as you see here, I kept things simple, only one module per folder, this is my preference as sometimes I do find use for more than one, sometimes up to 10, but for the sake of this, I’ll keep it at one per folder. Another reason is I can afford to not have to worry about where I put the module, as long as I can get around just as well, I say this because of a few simple lines of code that do wonders

So, let’s go to the main script here

So, we’re inside of the server “main” script, all we need to do really is.

local fileSystem = script.Parent

for i,module in next, fileSystem:GetDescendants() do
	if module:IsA("ModuleScript") then
		coroutine.wrap(function()
		module = require(module)
			if module.init then
				module:init()
			end
		end)()
	end
end 

That’s about it, I do have a entire util set up for myself, so I technically use this method but it’s a bit more advanced than that as it really helps my game development, and a little tip is to really get into modules and making utils for your server and client to maybe fit your project’s desires as a developer!

Moving on though, basically what this is doing is it loops through the entire filesystem and all of the folders, and if it finds init(Which should be a function) in the table that the module returns, then it will initiate the function, this particular system is designed so that you have the modules that are supposed to be initiated from the moment the server starts up, and the modules that are maybe there to be branched off from those.

That’s the gist of the structure, I have many things to add to this however I’d rather not go fully in depth into this more than needed so that’s the base-structure, how you choose to add to it is up to you though!

2 Likes