Quantcast Updating values using RegisterForUpdate() - ESOUI
Thread Tools Display Modes
03/30/18, 09:51 AM   #1
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 198
Updating values using RegisterForUpdate()

Hey,

I have to update duration values (represented by a label) of ~10 objects. Each object contains a control (Top level window) and it's data:

Code:
object.control = #userData
object.data = {
    ['durationInfo'] = {
        ['startTime'] = 0100.00000
        ['endTime'] = 120.12345,
    },
    ['someOtherData'] = {
        -- ...
    },
    ['evenMoreData'] = {
        -- ...
    }
}
All objects show the display duration, taken from self.data.durationInfo, as a label that gets updated ten times per second (= needed for a display that has a precision of one digit after the dot). Let's say our GetGameTimeSeconds() is 114.2, the displayed remaining duration would be 5.92345 seconds, rounded to and displayed as 5.9s.


Now the question: There is two ways of achieving it:

1) Registering one updater that iterates through all objects and sets their displayed durations

Code:
Addon:RegisterForUpdate("GenericUpdater", 100, OnUpdateHandler)

function Addon.OnUpdateHandler()
    local curTime = GetGameTimeSeconds()
    for objName, objData in pairs(Addon.objects) do
        local durationDisplay = objData.durationInfo.endTime - curTime
        Addon.objects[objName]:SetDuration(durationDisplay)
    end

    -- some other stuff that needs to be checked onRegisteredUpdate, too, there are ~4-5 other tables that are iterated here
end
2) Registering an updater for every single object that updates it
Code:
-- genericObj is the class that all objects inherit their methods from
function genericObj:New(controlName)
    -- setting up the metatable, controls, etc.
    -- ...
    -- ...
    -- ...

    genericObj:RegisterForUpdate(controlName, 100, genericObj.OnUpdate)
end

function genericObj.OnUpdate()
    local durationDisplay = self.data['endTime'] - curTime -- (curTime being defined somewhere and stored 
    'globally' in the addon class)
end

-- create an instance of the class genericObj
local testObject = genericObj:New("SuperDuperTestObject")

In short words: Should I register an updater for every object, that only handles itself, or should I register a 'monster updater' for the whole addon that updates every object that is part of the addon by iterating through it using a loop?

Last edited by Letho : 03/30/18 at 10:00 AM.
  Reply With Quote
03/30/18, 07:34 PM   #2
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 434
Since the goal appears to be to update them simultaneously any way: I don't know of any benefit to making them all independently do the same thing when you could just have the parent refreshing function handle all of them at once.
  Reply With Quote
03/31/18, 03:05 AM   #3
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 198
Yes, Chip helped with this on gitter, yesterday and he told us the same. Using as few updaters as possible is mostly the best solution.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Updating values using RegisterForUpdate()

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off