Thread Tools Display Modes
08-19-08, 01:46 AM   #1
Selite
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 20
LDB implementation questions

Ok, I think I've got it right, but I thought I'd just a couple of questions.

1. In the data feed example here there is the line;
Code:
f:SetScript("OnUpdate", function(self, elap)
Just want to know when "OnUpdate" actually fires.

2. In the line;
Code:
    dataobj.text = string.format("%.1f FPS", fps)
This is less to do with LDB, but while I'm here, I thought I'd ask. The %.1f gets replaced with the variable fps, and is rounded off to 1 decimal place, right?

Thanks in advance.
  Reply With Quote
08-19-08, 02:02 AM   #2
rodrick
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 34
First one . . . you need to know when OnUpdate fires in relation to what? Last call? Script start? real time?

as for the second part of your post yes that's what it does . . . returns a compacted float to that decimal. See the examples here: http://www.wowwiki.com/API_format
  Reply With Quote
08-19-08, 02:16 AM   #3
Selite
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 20
When OnUpdate fires in relation to Script start, and after each sucessive call.

The idea I got from looking at the code was that it was called quite often, and the function dealt with the actual string updating, but upon closer inspection it seems I can set the actual updates to fire when the string updates with the code
Code:
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local function mycallback(event, name, key, value, dataobj)
    ChatFrame1:AddMessage("LDB: myDataAddon.text was changed to ".. tostring(value))
end
ldb.RegisterCallback("MyAnonCallback",LibDataBroker_AttributeChanged_myDataAddon_text", mycallback)
Or something similar.
  Reply With Quote
08-19-08, 02:25 AM   #4
rodrick
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 34
I think you are misunderstanding. That OnUpdate is just a normal frame's OnUpdate and it's being used as a timer. Don't want to update the LDB display every OnUpdate as that's QUITE often and will certainly slowdown the client for such a simple amount of code. Basically that code runs every "frame" where frame is probably not quite as often as a screen redraw but quite quick nontheless.

Code:
    elapsed = elapsed + elap
    if elapsed < UPDATEPERIOD then return end

    elapsed = 0
That part is where it adds up the amount of time between calls and if it's not time yet returns . . . if it IS time on the other hand . . . zero out the elapsed and run the code.

It will probably help if I know what kind of LDB plugin you are attempting to make?
  Reply With Quote
08-19-08, 02:28 AM   #5
rodrick
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 34
Originally Posted by Selite View Post
When OnUpdate fires in relation to Script start, and after each sucessive call.

The idea I got from looking at the code was that it was called quite often, and the function dealt with the actual string updating, but upon closer inspection it seems I can set the actual updates to fire when the string updates with the code
Code:
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local function mycallback(event, name, key, value, dataobj)
    ChatFrame1:AddMessage("LDB: myDataAddon.text was changed to ".. tostring(value))
end
ldb.RegisterCallback("MyAnonCallback",LibDataBroker_AttributeChanged_myDataAddon_text", mycallback)
Or something similar.
What you are doing up there is registering to be notified when the addon updates the text. (note: I haven't actually looked to see if that's the correct way of doing it though) You should already know when the LDB plugin should update as you are the one that's updating it I assume? Or are you trying to make a display? (ie fubar clone)
  Reply With Quote
08-19-08, 02:31 AM   #6
rodrick
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 34
ok since I'm going to bed . . . if you just wish to update the text the command:
Code:
dataobj.text = string.format("%.1f FPS", fps)
is really the meat of it. (Yes that's pretty much it, it's simpler than you are making it I am thinking)

Good luck I'll check this after I wake my rear end up.
  Reply With Quote
08-19-08, 02:43 AM   #7
Selite
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 20
Originally Posted by rodrick View Post
I think you are misunderstanding. That OnUpdate is just a normal frame's OnUpdate and it's being used as a timer. Don't want to update the LDB display every OnUpdate as that's QUITE often and will certainly slowdown the client for such a simple amount of code. Basically that code runs every "frame" where frame is probably not quite as often as a screen redraw but quite quick nontheless.

That part is where it adds up the amount of time between calls and if it's not time yet returns . . . if it IS time on the other hand . . . zero out the elapsed and run the code.

It will probably help if I know what kind of LDB plugin you are attempting to make?
Starting with your final question, I'm trying to make a data feed to display the number of XP gains (calculated from the last gain gotten) to level. So, I know when I need to update the LDB feed, so could I just add in ....

Just read your newer post. So, I'd just add in a new line to my OnEvent code that updates the dataobj.text var whenever it needs to be updated.

So my final code (for updating the feed) would end up being something like.
Code:
-- Called at OnEvent
function SelXP_OnEvent()
    if ( event == "PLAYER_XP_UPDATE" ) then
        -- getting & setting variables, doing math.
        dataobj.text = string.format("%.1f Reps, Sel_Reps)
    end
end
Correct?

I'll try it out in a little while, and tell you if it works.
  Reply With Quote
08-19-08, 12:25 PM   #8
rodrick
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 34
That looks right to me. Good luck.
  Reply With Quote
08-20-08, 03:21 AM   #9
Selite
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 20
A little bit of tinkering managed to get me a working feed.

I'll probibly write a 'How To' sometime in the next couple of days, because this is still not crystal clear to me, and if I replicate it a few times, I'll probibly get the theory behind it into my head.

Thanks again.

...Sel.
  Reply With Quote
08-20-08, 05:51 AM   #10
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by rodrick View Post
Basically that code runs every "frame" where frame is probably not quite as often as a screen redraw
btw: OnUpdate is done once on every screen redraw (at least afaik)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » LDB implementation questions


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