eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 23 Nov 2012 01:03 PM |
I'm coding my whole game in a single script, so it's starting to get messy and I'm having trouble to find the line I want.
I've always thought that coding everything in a single script reduces lag because it takes up less data cost, but I like to keep my code organized. Is it more efficient to split up the script into smaller scripts, or do I keep it like that? |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 23 Nov 2012 01:06 PM |
No. One big script > Multiple lower ones.
But of course you should split it up when it's getting big, big big,...>1k lines or so? |
|
|
| Report Abuse |
|
|
|
| 23 Nov 2012 01:06 PM |
I'm pretty sure you can do CTRL+F...
If not, then just re-organize your code and have standardized variables.
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ |
|
|
| Report Abuse |
|
|
|
| 23 Nov 2012 01:19 PM |
| Organize it into sections that would have been the other scripts, then tag those sections with comments and use CTRL+F to find them later! |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 23 Nov 2012 01:19 PM |
| I suggest organizing your code into a class based system. :) |
|
|
| Report Abuse |
|
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 23 Nov 2012 01:24 PM |
| That's a brilliant idea, I'll consider it :D |
|
|
| Report Abuse |
|
|
|
| 24 Nov 2012 07:20 PM |
| I've been working on script builders for so long I forget you can divide things into smaller scripts... I prefer one huge, 2k lines longs block of gorgeous code, honestly. |
|
|
| Report Abuse |
|
|
|
| 24 Nov 2012 07:38 PM |
@Quenty,
Great minds think alike. |
|
|
| Report Abuse |
|
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 24 Nov 2012 07:39 PM |
"I prefer one huge, 2k lines longs block of gorgeous code, honestly."
Only if it's tidy. I like neat code, but I'm too lazy to organize it. Splitting it up would make the job easier, but I'd have to declare a lot of variables again.
I've decided I'll just make CTRL+F checkpoints so I don't get lost while scrolling. |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 25 Nov 2012 01:44 AM |
If your code is that long, make sure to localize functions and such. Example:
local math.floor = math.floor
(You could steal Quenty's pre-localize thing that he uses) |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2012 08:37 AM |
I always use CTRL + F when I need to find a specific line. Here are some steps in case you don't know how to do it:
1.) Open your script, click anywhere on the first line
2.) Type in the blank a keyword that may be in the line you are looking for
3.) Click 'Next' or 'Down' until you find the line you are looking for
*NOTE* The word you are searching for is probably going to show up more than once in your script, just keep clicking 'Next' or 'Down' until you find it |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2012 09:33 AM |
It's easiest to make the script communicate when it's all written in the same script, but it's more convenient to do them in separate scripts.
Therefore, I do a nice hybrid. I make the scripts I'm writing automatically be converted into StringValues and a main script will load them. While loadstrings apparently aren't too quick, the functions only need to be loaded once, so it's no big deal.
And it's convenient in the way that if I have an infinite loop in three separate scripts, I can combine them all into one.
f1 = loadstring(); f2 = loadstring(); while true do f1(); f2(); wait(); end
This way, only my one script needs to be chugging along ad infinitum. |
|
|
| Report Abuse |
|
|
| |
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 25 Nov 2012 10:24 AM |
| That's too hacky, I prefer using CTRL+F :l |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2012 10:54 AM |
To allow having more than one while loop going forever, use delay hax as a pseudo-coroutine.
delay(0, function () while wait() do --watever end end) |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2012 11:13 AM |
| ^ how does that have to do with anything? |
|
|
| Report Abuse |
|
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
| |
|
|
| 25 Nov 2012 11:34 AM |
| Yeah, you can spawn new loops, but that means there would be multiple loops constantly waiting on the RunService to call it back. In all honesty, combining them into one loop probably doesn't improve performance in any noticeable way, but I like to think it does. |
|
|
| Report Abuse |
|
|
| |
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 25 Nov 2012 11:37 AM |
Wow, I'll quit using the long 'coroutine.resume(corutine.create())' way.
I've heard some people say 'coroutine.wrap' does the same, but it doesn't work for me. |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 25 Nov 2012 11:40 AM |
@eJorge,
No, no don't!
That's h44xy.
There's nothing wrong with coroutines. Besides, they make you look more professional, and people will understand your code instead of doing their head in trying to figure it out. |
|
|
| Report Abuse |
|
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 25 Nov 2012 11:51 AM |
| Lol, okay. I hardly ever give away my code anyway. |
|
|
| Report Abuse |
|
|
|
| 25 Nov 2012 12:32 PM |
Spawn() is way easier to read than coroutine.resume(coroutine.create()). Neither way is hackier than the other.
The only time I use coroutine.create is if I'm gonna be using yields and resumes. |
|
|
| Report Abuse |
|
|