Originally Posted by AJSTITAN14
To Seerah: Thanks again. #3 is the part i'm having the most difficulty understanding. I'll take a look at it again tomorrow.
|
lua Code:
function PrintStuff(thing, otherthing)
print(thing, otherthing)
end
PrintStuff("hello", "world")
This prints out
hello world
lua Code:
function PrintStuff(thing)
print(thing, otherthing)
end
PrintStuff("hello", "world")
This prints out
hello nil because the function is not passing through the second argument (otherthing). It's just looking for the first.
lua Code:
frame:SetScript("OnEvent", function(self)
print(event)
end)
This would print out
nil because event is not defined in the function. Remember, I said that the variables could be called whatever you wanted. Lua is not psychic, and can't assume what you're looking for.
lua Code:
frame:SetScript("OnEvent", function(event,self)
print(event, self)
end)
This prints out
"FrameName", NAME_OF_EVENT.
Below is what I came up with and I tried to imlement some of Seerah's suggestion in the naming and variable scope.
The code works but it's too slow . So that was what I was trying to accomplish today but it's not exactly what I had in mind. The default UI and other mods update the text value much faster. I guess my first question is:
Is that an actual stream of data that I can capture somehow or is it interpolated?
|
irt your most recent block of code, you're using ABFrame, but registering events via a second frame, MyFrame. While this doesn't hurt anything, it's best to follow the
K.I.S.S. principle.
Though I don't know why your code is executing slowly... It may be that you're calling UnitPower() twice instead of just using the PlayerEnergy variable that you just set... /shrug
Number two: if I don't need to check the event return how do I kick off the mod to update the data in the frame?
|
Picture this. You are waiting for your number to be called. You tell a friend to tap you on the shoulder if they hear it. If your friend taps you on the shoulder, you know that your number has been called - they don't need to say anything. Now, picture that you ask your friend to tap you on the shoulder if either your number gets called or if they see a cute girl. This time when your friend taps you on the shoulder, they need to tell you why they did - you're waiting for two taps.
Obviously, if your code gets more complex and you wait for multiple events, you'll want to check to see which one fired before you execute your code. But if you're only waiting for one, or you want to do the same thing for both/multiple events, then it doesn't matter. A tap on the shoulder means the same thing.
Checking for your event (by doing if event == "MY_EVENT"), like the above ABFrame vs. MyFrame stuff, doesn't hurt anything at all. It's just a way to save on an "if statement".
One thing to note, however, is that the
"UNIT_ENERGY" event fires whenever *any* unit's energy changes. You'll want to check to make sure it's yours before running code, else you'll be doing stuff when you don't need to. This may also be the cause of the "slowness" you mentioned. Since the event returns a value of the unit, your code will look like this.
lua Code:
ABFrame:RegisterEvent("UNIT_ENERGY")
ABFrame:SetScript("OnEvent", function(self, event, unit)
if unit == "player" then
Energy:SetText(UnitPower("player"))
end
end)
There are some other optimizations, etc. that we can do with your code, but we won't worry about them now.