meh, depends on what youre running. If its many core functions, then absolutely not. but if its just running one thing, then yes. But like some people in this forum said, it only matters about the content within the script, so dont go and just make a ton of lines, but then again dont try compacting it in like 1 line. Basically just try to make your code look neat and be effective.
The amount of lines doesn’t matter and you shouldn’t modularize for the sake of keeping the line count small, I got modules for my simulator ranging in size from 50 lines up to 2000 lines.
Make modules to keep stuff organized and efficient, and to prevent repeating code.
In my point of view, you can’t have “too much” lines of code. To organize it, put comments in convenient places in the script. No need to create a whole ton of extra scripts.
As most people above have said, it doesn’t really matter. The only thing to note however, is if the script codes for several different things. Ask yourself, “are these pieces of code for relatable functions?” If they are random, it might be helpful to split it up for organization’s sake.
Organization is one of the hallmarks of an efficient programmer.
However, sometimes code simply piles on. One script can start at 50 lines for just handling one case and evolve to 500+ because it has to handle many more.
If you only have one or two scripts total in the game, then that would probably pose the question of maybe being unorganized. If you want to join a developers team, or even go into the professional world, organization not only helps you but also helps everyone else who is helping you out.
Now, if you can read it then your fine. Just think of if others have to read it or even you from the far future has to. Never know when organization can speed productivity up.
Line-count in of itself should never be a consideration. I’ve worked on scripts that have spanned several thousand lines, but were perfectly pleasant to expand upon, as they were written properly. In the same vein, I’ve additionally seen very compact code that is unworkable due to its messy nature. There is no correlation.
As long as the code is both efficient in its current stratification, and expandable for anyone working upon it, then I wouldn’t damage its structure.
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
What if a game has 1 million lines becuase of super complex and super detailed game?
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.
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.
This is my own game called space arc, it’s very modularized,
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.
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
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.
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
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.”
As long as it isn’t just clicking ENTER 700 times…
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.
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.