700 lines? How much is TOO MUCH?

Stay on the right trick, you’re almost there!


No, there’s no such thing as exaggerating. There’s no too much in scripting. Some codes can go over 1000, and that’s fine.

If your script works, you’re on the right path. You just need to practice writing clean codes, with indentation and whitespace used properly so your code is readable. Don’t use too much line breaks, for example. Learn to simplify codes and use the appropriate/recommended style.

11 Likes

If your code is already relatively efficient, and as long as you can understand the parts of your code so you can make changes in the future, it can be as long as you like.

It really depends on what you’re making - if these 700 lines are just handling something small that could be done in < 100 lines, for example, then yeah you could do with reducing the lines so it’s easier to edit in the future - but if it does what you want it to do in 700 lines and you don’t think you could get it much smaller there isn’t really much point. It’s different for each game so you’ll have to determine if you think it’s an excessive amount of lines or not.

I have multiple scripts in my game Obby Creator which are 1000+ lines and in total there is probably around 3000-4000 in the whole game. But that doesn’t necessarily mean it’s written in an inefficient way, sometimes you just need a lot of code. I’m sure lots of top games have tens of thousands of lines.

Tl;dr only need to shorten the code if it’s horribly inefficient or you can’t understand it that well and it can be written in a much smaller way. No point in reducing the amount of lines if there isn’t much need to do so.

5 Likes

It doesnt really matters.

It depends upon you whether having a lot line of code or less line of code helps you or not.

Look at your script and ask questions like;

  • Is it readable/understandable?
  • Will I be able to edit this code after a long time?
  • Is it necessary?

Though from mine point of view maybe having less amount of code i.e (>200) per script is good.

1 Like

The lines won’t matter if the game runs!

1 Like

Well 700 lines is not too much. Most game developers use more over that 700+ lines of code. Especially for big games. Including module scripts. Most big games have more than 1000+ lines inside each their script (for game mechanics). I tell you what, when I was making a boss battle system, my script had over 3000+ lines. Which is big enough for the entire script. So 700 lines is normal.

You shouldn’t worry about line count at all.

You should focus on making sure your code works, is efficient and clean.

6 Likes

Lines don’t matter.

All it comes down to is organization and efficiency. Module scripts would be the key

1 Like

“Too much” should be defined as how many lines until your computer starts having difficulties. I had an issue with a very laggy scripting interface on my old computer (~2900 lines), but after switching computers I’m sitting at about ~4000 lines and counting without issue. Generally, if what you’re working on gets so big to where it interferes with how you work, then you might want to branch your script off via ModuleScript or something along those lines.

If there are multiple parts of your code that can run independently but don’t have a real correlation to how your script operates, (e.g. minigames, like AstroCode said), then feel free to branch such things

All in all, line count doesn’t matter. What does matter is how you write your code.

2 Likes

How many lines a script has doesn’t decide wether that script is efficient or not. A script with 1000 lines can run faster than a script that contains just 1 while loop. What those 680 lines have in them is what tells you how efficient your script is, its contents, over-use of while loops/renderstepped, redundant pieces of code, repeated sections that could’ve been avoided ect.

Having all code in one script isn’t a problem from what I know performance wise, I always see people stacking all their code inside of module scripts.

1 Like

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.

2 Likes

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.

1 Like

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.

2 Likes

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)