| Improve Coding | |
|
|
|
Author | Message |
---|
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Improve Coding January 20th 2011, 7:39 pm | |
| I'm not sure if this belongs here, but anyway. There are many ways to code. Some better than others. For example, a recent project of mine has to communicate and interact across the Workspace with other scripts constantly. The problem? I had two options. One would be to use multiple scripts for the same amount of work, creating more lag. My choice? I used coroutines, consecutive functions, and 'shared' to store data. My choice was much less laggy and kept the Workspace looking usable. But on to improving your scripts. ------------------------------------------------------------------------------------------------------- 1. Instead of while true do wait(), I always use while wait() do. This saves you a decent amount of space eventually if your script has many while-do statements. 2. Pretend we were trying to insert a message. When using Instance.new, never do this except for readablity: - Code:
-
obj = Instance.new("Message") obj.Parent = Workspace obj.Text = "Test" A way to condense this into a small amount is to take advantage of an arguement some people ignore. - Code:
-
Instance.new("Message",Workspace).Text = "Test" 3. Take advantage of coroutines to prevent wasted script space. For example, instead of having one script checking for newly inserted parts, and another changing the time, we can combine them - Code:
-
coroutine.resume(coroutine.create(function () while wait() do --time changer end end)) function function1(a) if a.className == "Part" then --blah end end game.Workspace.ChildAdded:connect(function1) 4. Remove whitespace and comments. The script has to still read whitespace and comments, so it results in wasted space and script time. If you use these as organization, remove them once your done. 5. Local vairables are called much faster than non-local. If you only need a variable for a small amount of code, just make it local to that function. - Code:
-
d = "hi" function hi() print(d) end --instead of that ^ do this function hi() local d = "hi" print(d) end I'm not done. I just got tired of typing for now
Last edited by naknak on January 22nd 2011, 1:38 pm; edited 1 time in total | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Improve Coding January 22nd 2011, 3:19 am | |
| don't forget local variables, they're called much faster than global! | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding January 22nd 2011, 1:34 pm | |
| | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: Improve Coding January 22nd 2011, 4:11 pm | |
| hey! i was the one who said that first! jk lol. no rly. i was. | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding January 22nd 2011, 4:33 pm | |
| | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Improve Coding January 23rd 2011, 4:32 am | |
| i already knew about local variables being called faster than normal variables before you told us. | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding January 23rd 2011, 3:09 pm | |
| The only reason I don't use them is because it broke one of my more lengthy scripts and I somehow can't fix it now... | |
|
| |
Supernapalm Expert Scripter
Posts : 393 Join date : 2011-01-17
| Subject: Re: Improve Coding January 23rd 2011, 7:48 pm | |
| | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding January 23rd 2011, 9:08 pm | |
| I fixed it finally! My brain was too numbed to fix it last night. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Improve Coding January 26th 2011, 8:36 am | |
| | |
|
| |
m27frogy The Garbageman
Posts : 336 Join date : 2011-06-23
| Subject: Re: Improve Coding June 30th 2011, 11:35 am | |
| | |
|
| |
m27frogy The Garbageman
Posts : 336 Join date : 2011-06-23
| Subject: Re: Improve Coding June 30th 2011, 11:41 am | |
| I would disagree with your comment whitewash though. What happens if someone else wants to edit your Free model script and no comments!! Major pain. Also, how much time is actually taken up reading these comments? 0.001 of a second? Plus, the Roblox admins sure didn't think comments were bad, their scripts are full of them! If the source code for the website has 'em everywhere! Overall, doing so would violate one of the many rules for good, strong, structured programming. Make it simple and be able to come back to it several months later and be able to quickly figure out how to fix it, instead of having to figure out how the script works all over again! | |
|
| |
m27frogy The Garbageman
Posts : 336 Join date : 2011-06-23
| Subject: Re: Improve Coding June 30th 2011, 11:42 am | |
| I was tought programming from a colledge aproach, even though I'm not even close to colledge. All the resources I read made it very clear that there had to be comments in any good code that was meant to be usable by anyone other than you. | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding June 30th 2011, 11:47 am | |
| Very true. I am probably going to start using comments again, I lost track of some of the things I made so I have to re-figure them out. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Improve Coding February 4th 2012, 8:07 am | |
| I think lua would precompile the syntax and would remove things like comments before it is run, so I doubt it would make a difference... | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding February 5th 2012, 1:37 am | |
| That, I don't know. I heard somewhere it makes it faster, but it doesn't make it easier to return to later. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Improve Coding February 5th 2012, 6:48 am | |
| lol my admin commands has a line with so many whitespaces that it reachs the limit for a line :P (I was trying to hide some code where people don't look) | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding February 11th 2012, 1:28 am | |
| Obfuscate the parts you don't want touched. Or the whole thing. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Improve Coding February 11th 2012, 7:50 am | |
| meh, I'm gonna make it free source to edit code, but I'm gonna add a delayed virus into it so it's a trial version that works for 1 week after inserting it and then it removes itself and the map! mwhahahaha, never trust my huge open source stuff >:D | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding February 11th 2012, 5:05 pm | |
| Ctrl+A, find where the blue space looks suspiciously long, scroll to the end, delete. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Improve Coding February 16th 2012, 2:32 am | |
| dang X_X but most noobs wont even open the script apart from inserting their name into it >:D | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding February 19th 2012, 11:22 pm | |
| That is true. But you want to hit as many people as possible. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Improve Coding February 22nd 2012, 6:44 am | |
| yea, I'll just encrypt every thing except for the admin lists. (in the encrypted part of the code if will insert my name >:) | |
|
| |
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Improve Coding February 23rd 2012, 12:08 am | |
| Obfuscate, don't encrypt. Encryption can be reversed and stolen, obfuscate can be only slightly reversed and is not worth the effort to steal. | |
|
| |
blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Improve Coding February 25th 2012, 3:53 pm | |
| wait, what the difference???? O_O | |
|
| |
Sponsored content
| Subject: Re: Improve Coding | |
| |
|
| |
| Improve Coding | |
|