Okay, on to the actual code. First of all, your indentation is weird. These are at the same heirarchical level; why are they indented differently?
Code:
local bftcf = CreateFrame('Button', 'BladeFlurryTargetCountFrame', UIParent)
bftcf:SetSize(50,50)
bftcf:SetPoint('CENTER', UIParent, 'CENTER')
bftcf:Hide()
bftcf:RegisterEvent('PLAYER_ENTERING_WORLD')
bftcf:RegisterUnitEvent('UNIT_AURA', 'player')
Unless you want to wrap all but the first line there in a do/end block, those lines shouldn't be indented.
Secondly, your code in its current state won't work at all, and should throw errors. For example:
Code:
bftcf:SetScript('OnEvent', function(self, elapsed, unit)
if (event == 'PLAYER_ENTERING_WORLD' and InCombatLockdown()) or (event == 'UNIT_AURA' and InCombatLockdown()) then
if UnitBuff('player', 'Blade Flurry') then
bftcf:Show()
bftcf:SetScript('OnUpdate', bftcupdater)
...
local bftcupdater = function('OnUpdate', self, elapsed, updater, cleaner, bladeflurrytargets)
updater = updater + elapsed
cleaner = cleaner + elapsed
#1 - You're naming the second value passed into your OnEvent script "elapsed" and then referring to a variable "event" that isn't defined. The checks against "event" will always fail, either because "event" is nil, or because "event" is some random unknown value leaked by another addon. You should change "elapsed" to "event" here, because the second value passed into an OnEvent script is a string containing the name of the event being handled.
#2 - There's also no need to check the events, because those are the only events you're registered for. Your frame cannot receive any events other than those two.
#3 - Checking InCombatLockdown() here is very inefficient. If you don't want to handle aura events out of combat, you should register for PLAYER_REGEN_DISABLED (entering combat) and PLAYER_REGEN_ENABLED (leaving combat) and register/unregister UNIT_AURA as needed. If you do this then you will need to check the event in your OnEvent handler after all.
#4 - In the scope where you're setting your OnUpdate script, "bftcupdater" is nil, because it's not defined until about 20 lines further down in the file, and is defined as a local. Unless you're creating globals (don't) you must define your variables closer to the top of the file than where you use them.
#5 - When you define "bftcupdater" you wrote "OnUpdate" inside the parenthesis. This should generate an error, because you cannot write strings, numbers, etc. there -- you're defining a function, not calling it. When your function is called, each of the things you wrote there is assigned as a variable, and given a value according to what's passed into the function. What you wrote would be like trying to do
local "OnUpdate" = 5 which just doesn't work.
#6 - If you're setting this as an OnUpdate script, then it will only ever receive two arguments. The first argument is a reference to the frame the script is set on, and is typically named "self". The second is a number describing how many seconds have passed since the last time the OnUpdate script was run, and is typically named "elapsed". You are assigning two variables with those names, but in the wrong positions, and you're also assigning three more variables ("updater", "cleaner", and "bladeflurrytargets") which will always be given nil values. The next two lines will fail and throw errors about attempting to perform arithmetic on nil values. I'm guessing you actually want to use the variables with the same names that you defined at the top of your file, in which case you need to remove them from the list of function arguments.
There's probably more, but there's no point in looking at anything else at this point. There's just no way this code could ever work as written. You should really at least load your code in-game and try to fix the errors before you ask for advice on optimization. Remember:
The First Rule of Program Optimization: Don't do it.
The Second Rule of Program Optimization (for experts only!): Don't do it yet.
|