Thread Tools Display Modes
03/01/14, 09:44 PM   #1
Krik
Join Date: Feb 2014
Posts: 8
Working with Events

Since the server is down and I can't test things maybe instead of pulling my hair out I can ask a few questions here.

First, in the MyFirstAddon tutorial, the xml file use an "OnUpdate" element to trigger a function
Code:
        <OnUpdate>
                MyFirstAddOnUpdate()
        </OnUpdate>
Is there a way to trigger the "OnUpdate" using lua only? I searched the wiki but didn't see anything that stood out.

Second, been tinkering with the EVENT_PLAYER_COMBAT_STATE.
lua Code:
  1. KrikMod:RegisterForEvent(EVENT_PLAYER_COMBAT_STATE, PlayerCombatState)
For testing I just store the boolean value in a global variable, and then a function checks the value and performs different actions based on the value returned. I guess I don't quite get how the "RegisterForEvent" works, because if I enter combat the function will output the test text I have it generating. But if I leave combat it doesn't do anything. I am not sure what to think of it yet need to do some more testing once the servers are back, but since I am waiting I'll see if someone has an answer.
  Reply With Quote
03/02/14, 05:23 AM   #2
zork
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 29
OnUpdate handler Lua side:

Lua Code:
  1. local function OnUpdate(...)
  2.   d(...)
  3. end
  4.  
  5. control:SetHandler("OnUpdate", OnUpdate)

To reset it I think you just have to do

Lua Code:
  1. control:SetHandler("OnUpdate", nil)
  Reply With Quote
03/02/14, 09:14 PM   #3
Krik
Join Date: Feb 2014
Posts: 8
Thanks for the tip. I think that will prove quite handy and it gives me additional insight to other parts of the API.

I got to thinking, after posting, the "OnUpdate" runs far to often for good performance. So while it may not be the best I have it set to run my code every 250 milliseconds.
lua Code:
  1. function OnUpdate()
  2.  
  3.     if (GetGameTimeMilliseconds() - KM.vars.prevruntime > 250) then  
  4.         KCT.vars.prevruntime = GetGameTimeMilliseconds()
  5.  
  6.         -- code to run every 250 milliseconds
  7.     end
  8. end

Now to the second question in my post. I did some testing and found the problem. The wiki say
EVENT_PLAYER_COMBAT_STATE (bool inCombat)
its actually should say something like
EVENT_PLAYER_COMBAT_STATE (integer eventCode, bool inCombat)
In fact now that I am looking some of the other events in the wiki are missing that first integer. I would maybe even assume all events would have an event code as the first variable??? For anyone learning the API that's going to cause huge amounts of confusion.
  Reply With Quote
03/02/14, 09:30 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
You don't need to call GetGameTimeMilliseconds(). There are two args passed through to your OnUpdate function. The first is the frame that the OnUpdate is running for. The second is the game time in milliseconds.


/edit: re. another question... The event handler is what is getting/passing through the event code. This is so the handler knows which event was fired (and you can do a check to make sure it is the event you want, if using the same function for more than one event). But some events provide their own returns - these are what are listed in the docs.

Last edited by Seerah : 03/02/14 at 09:33 PM.
  Reply With Quote
03/02/14, 11:14 PM   #5
Krik
Join Date: Feb 2014
Posts: 8
Originally Posted by Seerah View Post
You don't need to call GetGameTimeMilliseconds(). There are two args passed through to your OnUpdate function. The first is the frame that the OnUpdate is running for. The second is the game time in milliseconds. .
Good to know, this kind of information needs to be somewhere in the wiki, it would make a lot of programers lives easier. But since the Beta has now ended I'll have to test that next time.
  Reply With Quote
03/02/14, 11:26 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
When unsure of what gets passed through functions or script handlers, do something like this:
Lua Code:
  1. control:SetHandler("OnUpdate", function(...) d(...) end)

Or...
Lua Code:
  1. d(GetUnitBuffInfo("player", 1))

The d() function in ESO will dump everything to your chat frame.
  Reply With Quote
03/03/14, 01:43 AM   #7
Krik
Join Date: Feb 2014
Posts: 8
Again another great piece of information, that I will definitely tap at the next round of beta testing.

I use to do mods about 5 or 6 years ago in WoW, haven't touch Lua since. However I do a lot of programing, I have worked with somewhere around 13 programing languages in the 20+ year I have been programming. Some of the work I do is fixing what someone else has screwed up and I have some great techniques for finding information about functions and bugs when working with someone else's code. Of course all my techniques have been developed over years of experience. This beta was 2 and a half days, in which I managed to get a very simple mod completed (no screenshots so I can't upload it yet, one more test run wouldn't hurt either). So I really didn't feel I had the time to look into ways to extract how the functions works. Of course as soon as I see that part of me goes duh, I keep seeing things that remind me of one programming language or another. And that's the other hassles I ran into this weekend. I am use to needing to look up xyz function in abc language (you can't know everything), but with Lua anytime I tried doing a search all that came up was stuff related to WoW. I would guess some of the results would have the answer, but I would need a better working knowledge of the WoW API to parse out the irrelevant parts. Lua is a super easy language but with all the information buried in obscure websites it makes it much more difficult than it really is.

Oh did I mention, again, that should be in the wiki. Anyone that knows programing knows that techniques like that are worth their weight in gold and can save huge amounts of time and hassle just having that info readily available.

EDIT: after posting that I thought got any other good tips

EDIT: A continuation of the previous edit. Maybe there should be a sticky'ed tips a tricks thread. If you can get 4 or 5 good tips in that and it could really prove useful.

Last edited by Krik : 03/03/14 at 01:53 AM.
  Reply With Quote
03/03/14, 02:08 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
When I have time I will go through the wiki.

re. a place to post and find tips, there is this forum: http://www.esoui.com/forums/forumdisplay.php?f=172
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Working with Events


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