WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   LDB implementation questions (https://www.wowinterface.com/forums/showthread.php?t=17783)

Selite 08-19-08 01:46 AM

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.

rodrick 08-19-08 02:02 AM

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

Selite 08-19-08 02:16 AM

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.

rodrick 08-19-08 02:25 AM

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?

rodrick 08-19-08 02:28 AM

Quote:

Originally Posted by Selite (Post 99412)
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)

rodrick 08-19-08 02:31 AM

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.

Selite 08-19-08 02:43 AM

Quote:

Originally Posted by rodrick (Post 99413)
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.

rodrick 08-19-08 12:25 PM

That looks right to me. Good luck.

Selite 08-20-08 03:21 AM

A little bit of tinkering managed to get me a working feed. :banana:

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.

Duugu 08-20-08 05:51 AM

Quote:

Originally Posted by rodrick (Post 99413)
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)


All times are GMT -6. The time now is 08:05 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI