He is basically saying that an integer loop is faster than ipairs. But... to be honest...
that really does not matter. You are not doing any stuff which needs a optimized
performance. Your code is fine. The only thing I would criticize is that you are not
covering every minimap button, only those in your table. You could do something like this
to get every button:
Lua Code:
local excluded = {};
local buttons = {};
local function initButtons()
for _, frame in pairs({ Minimap, MinimapBackdrop }) do
local children = frame:GetNumChildren();
for i = 1, children do
local button = select(i, frame:GetChildren());
if (isValidButton(button) then
tinsert(self.buttons, button);
end
end
end
end
-- validation could be something like:
local function isValidButton(button)
if (not button) then
return false;
end
if (not button:IsVisible()) then
return false;
end
if (not button:GetName()) then
return false;
end
if (not (button:GetWidth() > 14 and button:GetWidth() < 55)) then
return false;
end -- questionable restriction
if (not (button:IsObjectType("Button") or button:IsObjectType("Frame"))) then
return false;
end
-- exclude those buttons, which are in the excluded list
for _, value in pairs(excluded) do
if (string.find(button:GetName(), value)) then
return false;
end
end
return true;
end
In general I would always recommend to choose speaking variables and function names.
Also I would recommend anyone who starts to code in any programming language to
get to know the basic programming and engineering skills.
Originally Posted by fusionpit
It'll probably be hard, because the two hardest things in software development are regular expressions, naming things, and off-by-one errors.
|
THIS!