A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 8th 2016, 10:14 am by naknak

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
July 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
July 6th 2015, 4:16 pm by m27frogy

» Ambassador!
April 15th 2015, 11:40 pm by naknak

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 13th 2015, 4:54 pm by naknak

» Who's active?!
April 13th 2015, 4:52 pm by naknak

» Where to go from here.
April 13th 2015, 4:51 pm by naknak

» Genesis Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 10th 2014, 11:43 am by naknak

» local scripts?
July 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
July 10th 2014, 11:36 am by naknak

» Hi. I am new here
April 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
January 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
January 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
January 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
November 26th 2013, 3:33 pm by Keanu73

» Improve Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


Share | 
 

 Improve Coding

View previous topic View next topic Go down 
Go to page : 1, 2  Next
AuthorMessage
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: 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
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Improve Coding   January 22nd 2011, 3:19 am

don't forget local variables, they're called much faster than global!

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Improve Coding   January 22nd 2011, 1:34 pm

I'll add it in, thanks!
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Improve Coding   January 22nd 2011, 4:11 pm

hey! i was the one who said that first! jk lol. no rly. i was.
Back to top Go down
http://hackthissite.org
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Improve Coding   January 22nd 2011, 4:33 pm

I know, but I forgot.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: 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.

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: 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...
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter


Posts : 393
Join date : 2011-01-17

PostSubject: Re: Improve Coding   January 23rd 2011, 7:48 pm

oh
Back to top Go down
http://hackthissite.org
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Improve Coding   January 23rd 2011, 9:08 pm

I fixed it finally! My brain was too numbed to fix it last night.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Improve Coding   January 26th 2011, 8:36 am

lawl

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
m27frogy
The Garbageman
avatar

Posts : 336
Join date : 2011-06-23

PostSubject: Re: Improve Coding   June 30th 2011, 11:35 am

XD
Back to top Go down
m27frogy
The Garbageman
avatar

Posts : 336
Join date : 2011-06-23

PostSubject: 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!
Back to top Go down
m27frogy
The Garbageman
avatar

Posts : 336
Join date : 2011-06-23

PostSubject: 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.
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: 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.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: 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...

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: 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.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: 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)

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Improve Coding   February 11th 2012, 1:28 am

Obfuscate the parts you don't want touched. Or the whole thing.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: 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

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Improve Coding   February 11th 2012, 5:05 pm

Ctrl+A, find where the blue space looks suspiciously long, scroll to the end, delete.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: 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

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Improve Coding   February 19th 2012, 11:22 pm

That is true. But you want to hit as many people as possible.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: 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 >:)

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: 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.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Improve Coding   February 25th 2012, 3:53 pm

wait, what the difference???? O_O

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Sponsored content




PostSubject: Re: Improve Coding   

Back to top Go down
 
Improve Coding
View previous topic View next topic Back to top 
Page 1 of 2Go to page : 1, 2  Next
 Similar topics
-
» What do you think Bearville should improve on?
» Improve your ping in China even to EU/US/Taiwan server
» it's better to improve the limitation of multilogging
» DeAveiro Basketball Skills Development Program
» Revival of Memories, by Brian E. Lowe (Schabbs) - coding by MCS

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Advanced-
Jump to: