What?
If you have ever had a server running lot's of scripts, you may have noticed poor performance coming from your Lua Engine. Well, there's a solution.
Why?
Well, when you create a variable you actually just make a new key in the _G table. If you don't know about Tables, go here. Therefore,
Code:
my_var = 1
is the same as
It does the same for functions. Every function you create is stored on _G. That's pretty much everything.
Imagine, trying to remember everyone in a High School's locker combination. Now imagine you had someone remembering the combo for every locker. A lot easier for you, eh?Yes, I'm Canadian.
Great..? Now How do I Fix This?
Simple. We have to store everything on separate tables. This is easy for Variables, as we showed before. It's just as easy, if not easier for Functions! Simple put the Table name before the function name, and put a period in between them:
Code:
var = 0
function doSomething(Unit, Event, Player)
var = 5
end
Should be
Code:
someTable = {}
function someTable.doSomething(Unit, Event, Player)
someTable["var"] = 5
end