Originally Posted by jeruku
Lua Code:
-- Move global functions into the frames table; you could also make them locals, like below, but I prefer this method. -- local GetWorldPosFromMapPos = C_Map.GetWorldPosFromMapPos tMinimapCoordsFrame.MapRects = {} tMinimapCoordsFrame.UnitPosition = UnitPosition tMinimapCoordsFrame.GetWorldPosFromMapPos = C_Map.GetWorldPosFromMapPos tMinimapCoordsFrame.CreateVector2D = CreateVector2D
|
Moving local references to globals into a table defeats the purpose of making them in the first place, which is to save on indexing operations. You run the same number of these operations pulling them from your table as you would calling them as globals.
Originally Posted by jeruku
Lua Code:
-- I dislike strings in OnUpdate; again, personal preference. tMinimapCoordsFrame.FromattedString = '%.1f, %.1f' tMinimapCoordsFrame.PlayerToken = 'player'
|
These actually create indexing operations in the following OnUpdate script as opposed to them being stored as a part of the function binary as a constant. All literal values are constants referred to when used in an expression. In the long run, this actually slows down the function instead of offering any performance boost.
Originally Posted by jeruku
Lua Code:
local function Blank_OnUpdate() end local OnUpdate = Blank_OnUpdate tMinimapCoordsFrame:HookScript('OnUpdate', OnUpdate) -- Getting the mapID every OnUpdate is rather inefficient, get it when it changes/loads local GetBestMapForUnit = C_Map.GetBestMapForUnit tMinimapCoordsFrame:HookScript('OnEvent', function(self, event, ...) if event == 'PLAYER_STARTED_MOVING' then -- Self explanatory event OnUpdate = Do_OnUpdate elseif event == 'PLAYER_STOPPED_MOVING' then OnUpdate = Blank_OnUpdate elseif event == 'ZONE_CHANGED' or event == 'ZONE_CHANGED_INDOORS' or event == 'ZONE_CHANGED_NEW_AREA' or event == 'PLAYER_ENTERING_WORLD' then self.mapID = GetBestMapForUnit('player') Do_OnUpdate(self, self.mapID) end end)
|
This way of swapping OnUpdate scripts doesn't work at all. It doesn't magically tell the function to watch
OnUpdate for changes, it just ends up grabbing
Blank_OnUpdate() on initialization and further changes in the event script does nothing. Since the OP used
:SetScript() to assign the function in the first place, it's safe to assume you can run
:SetScript("OnUpdate",nil) to clear and set it again when necessary. Otherwise, you can set an upvalue to flag and have the script check it when it's to run.