View Single Post
02/27/14, 04:41 AM   #1
zork
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 29
Doing everything via OnUpdate?!

I'm completly baffled by seeing this:

Code:
<GuiXml>
	<Controls>
		<TopLevelControl name="AddonName">
			<OnUpdate>
				AddonOnUpdate(self,time)
			</OnUpdate>
		</TopLevelControl>
	</Controls>
</GuiXml>
So from my understanding what currently some of the addons do is they use an OnUpdate function to simply do everything. To make it not freeze up your entire machine a buffer is set in place throttling the whole process.

What is wrong with doing this by event handlers?

Coming from the WoW API what I would do is init my basic frames and register some specific events to do stuff for me. There has to be unit specific or aura specific events right?
Is that because people don't know which events to use right now?

So here is what I would do.
  1. Create a basic addon frame and register EVENT_LOGIN_SUCCESSFUL and/or EVENT_ADD_ON_LOADED
  2. If my addon is loaded and I have access to my variables I set up my basic frames
  3. After that depending on purpose of my addon I would register matching events with certain OnEvent functions to do stuff for me.

Do not use OnUpdate for everything in your addon. This is really bad imo.

Use event handlers! ESO events: http://wiki.esoui.com/Events

If you need XML to initialize your addon do this:
(it may be possible that this is obsolete if you register the addon loaded event)
Code:
<GuiXml>
    <Controls>
        <TopLevelControl name="AddonName">
            <OnInitialized>
                AddonOnInitialized()
            </OnInitialized> 
        </TopLevelControl>
    </Controls>
</GuiXml>
A really good example of how to work with event handlers can be seen in the code of DragonLoot.
http://www.esoui.com/downloads/info1...LootAddon.html

What I have not wrapped my head around yet is the event registering itself. DragonLoot uses two types of event registering. One on a global event manager and the others for the addon itself which seems to part of the global namespace after init.

Lua Code:
  1. local manager = GetEventManager()
  2. manager:RegisterForEvent("UniqueEventIdentifier", EventName, OnEventFunction)
  3. AddonName:RegisterForEvent(EventName, OnEventFunction)

Currently I'm not sure if you have to do it exactly that way. But it may be the case.

What you should be able to do aswell is unregistering of events. Like:

Lua Code:
  1. local manager = GetEventManager()
  2. manager:UnregisterForEvent("UniqueEventIdentifier", EventName)
  3. AddonName:UnregisterForEvent(EventName)

What would really help if we could access to the default ESO addons. Basically the Lua+XML files of the "EsoUI" folder that is packed in game0000.dat. It would help a ton.

Actually I have access to all of those files now but I doubt that we are allowed to post them to Github for code review. Or are we? It would be such a great help for learning how to write ESO addons.

Last edited by zork : 02/27/14 at 07:40 AM.
  Reply With Quote