I've looked at many scripts written by others before and I always see:
local unpack = unpack local print = print local next = next
and so on...
Why do they do this?
The term you are looking for is called Coaching.
Global Variables are around 10x slower than local
variables when you try to access them. Coaching is completely unnecessary unless you are doing something that could require it. Although, I doubt you would need anything that would require.
It is important to note that we do not assign local
to variables for the sake of the performance. We assign it because it is a good programming style as well as it avoids name collisions. Many people think that if I just do local print = print
, it will automatically become 10x faster. At this moment, we are looking at milliseconds (? Citation Needed) or even less. I don't think this is usually an issue unless you need that milliseconds. This again, can be easily countered by using a better algorithms and/or a better data structures.
In conclusion, coaching is really unnecessary but a choice if you do need it.
Since this question is more opinion-based (I'm pretty sure) - I'm responding with an answer instead of a comment.
Personally, I never do this. Especially redefining it as exactly what it is. I can understand it if you do something like
local p = print
and you use print a lot in your code - but I don't quite get the need to do what you've mentioned.
I do it mostly to save time. I know a lot of scripters who do this.
--[[ Let's assume you want a part's Cframe changed. But you're in a hurry. You can make a variable equal to Cframe.new to save time. --]] local cf = CFrame.new workspace.Part.CFrame = cf(0,0,0)
I dont really do this anymore, but keep in mind it works.
Locked by User#24403
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?