700 lines? How much is TOO MUCH?

Don’t worry, that’s hardly a lot of code. Most full games have tens or even hundreds of thousands of lines of code in some cases. Mine usually have 10k-70k lines. That said, I follow a few practices to avoid having an excessively large script.

I think the best way to keep scripts concise is to use module scripts. For example, if you need a part of your script to handle particle effects, throw it in a module scripts and use functions in the main script like Module:CalculateParticles() instead of putting a 300 line function into your main script.

Instead of having 30k long scripts, I usually just make a dozen module scripts, put them in folders based on their category (ie Data Stores, Effects, Map loading, chat, etc) and then just require() them into whatever code I need. This is also an excellent way to avoid repetition.You can also creatively use bindable events and bindable functions to communicate between two scripts.

All this being said, it’s okay to have scripts or modules that are a couple thousand lines long. My point is to cut down where possible, don’t just split a script in half.

If you do need to make a really long code block in one script, you can collapse it in the editor by clicking on the little ‘>’ arrow icon. You can also make code blocks using

do
     -- some code
end

And collapsing the do end block.

But like I said, use module scripts and don’t worry about having lots of code.

Finally:

Even if your game has 100,000 lines of code, that’s only 1 - 10 MB of data. Your hard drive can store LOTS of data, so even a game with 100,000 lines of code would only be a very small percentage of total storage.

EDIT: Excuse me, not 100 KB, I was stupid and got character count mixed up with line count.

If we assume that each line of code has 50 characters (from 20-100), 50 * 100,000 = 5,000,000 = 5 MB

5 Likes

What if a game has 1 million lines becuase of super complex and super detailed game?

1 Like

I am going to agree with the majority of posts here; there is no limit to how long your code should be.

If your code works efficiently and is easy to read then you are fine. Of course sometimes there are times where your code is unreasonably long, but that may be because of the method you’re applying.

If your code is really long and is hard to read or follow, try using modules. Modules allow you to break your code up into different scripts and libraries which can make it much easier to run down.

2 Likes

It’s really preference, I’ll give you 2 example games I work on that vary.
Phantom forces has a 18k+ line script and it runs fine. Organization wise, the modularization is going to beat it.
image

This is my own game called space arc, it’s very modularized,
image
Each part of the game, such as team systems, factions, rendering will get it’s own module script. This method makes finding what you’re looking for easier. I would definitely recommend good organized modules that will ultimately improve workflow later down the road when the game gets bigger code wise.

6 Likes

100kb of Data. To me it eats up all your memory (or storage)

What do players use with 18k lines? I’m not saying this so anyone can’t program at all but I’m wondering how many scripts they use.

Looks like a lot but im not sure how many lines though in each one exactly, or if that was just one of them

1 Like

It’s just overall game mechanics. Large complex games have tons of code, that’s actually only the icing on the cake. Overall it’s about 190k.

The main game programming is done in large scripts, but all guns, etc are in modules. Each gun will have its own. I’d recommend splitting your code up even more though. Let’s just say you have pets in your game, have 1 module on server and 1 on client to handle anything related to their functionality. Each different pet will have its unique data in separate module scripts, such as name, price, model, id, perks, etc.

1 Like

There isn’t really anything wrong with 700+ lines my client has more than that and I have yet to even finish working on the uis…

on side note I’d like to throw what I did for this game I’m working on
image

2 Likes

It depends on what you’re writing. There is no limit on how many lines you use, as long as your code is efficient I don’t see any problems with it being 700 lines.

Even with 50 MB of code that would only be 0.05% of a hard drives total storage assuming it’s a standard 1 TB HDD.

Even if there was 100 characters per line of code, that would be 100 MB. 1/10th of a gigabyte, so pretty large to download but usually hard drives are 1 TB or more, so that would be about 0.1% total storage.

As long as there is no problem, you should not worry about having “too many lines of code.” :blush:

As long as it isn’t just clicking ENTER 700 times… :crazy_face:

1 Like

Yes your script would run fine even though there are more than 700 lines of code. But if you don’t have a good computer and your game mechanics starts getting problem, I suggest you use ModuleScripts to ease the lines and also to divide them.

1 Like

Garge Games usually have 50,000 lines - 150,000 lines. However smaller games only need a few thousand for a good standard.

Code blocks are meant to do stuff, doing stuff requires time, consistency and hard work.

Havinig “too much code” is not an issue as the computer is able to read all of it incredibly fast.
It is also very good at repeating tasks.

My module just broke 1,244 lines of code due to it’s mechanics and complexity. I created this module for a custom character system for each specific teams. In this case, this is the Police character module:

image

Basically 700 lines of code is fine. As long as you understand your code and you’re organized. If there’s a lot of lines and your code is not organized then you should start cleaning it up until it’s fully debugged or something.

I just broke a thousand lines of code and my module is still working fine. It should do the same for you too.

I think you should make scripts shorter so that way you can keep track of it all. If there are scripts with a really big amount of lines you could lose track where everything is.

It really depends on what the script does, personally I write pretty long scripts, but if your main code is 680 lines long thats not that bad, if its your MAIN code.

It depends on what script you arr making, my script for saving parts is about 3.5k lines and the script to load them is another 3.5k lines which is 7k lines in total

700 isnt bad so long as it runs properly