Check if debuff exists in game
As the title says, I need help with error control.
The player types in the name of a debuff and if this debuff exists in the game then store it in the array debuffList. Code example follows: Lua Code:
|
There is no distinction between spells and "debuffs". What's happening here is just that Sunder Armor triggers a different spell. In this case, supposedly due to the Weakened Armor effect being "normalised" these days and triggered by several abilities.
http://www.wowhead.com/spell=7386 http://www.wowhead.com/spell=113746 Also, GetSpellInfo only works with names if they are in your spellbook. If you use spell ID it will always work. |
ah, thanks for clarifying.
Is there any easy way to get spellID from the spellName if you do not have the spell in your spellbook? |
Well. You could do sth else. You could register UNIT_AURA to a specific event frame.
Each time UNIT_AURA triggers you can check Lua Code:
All spells are spells. Some spells are auras. Some less spells are debuffs. UnitDebuff (aka. UnitAura, HARMFUL) may deliver even more values. You can check that by doing print(UnitDebuff(unit,i)). http://wowprogramming.com/docs/api/UnitAura |
I'm not sure if there's a performance benefit to declaring those local variables outside of the for loop, as they are reassigned each loop iteration anyway (although I could be wrong). There's also no need to explicitly initialize them to nil as this is the "default value" of a non-initialized variable anyway.
|
There's no benefit. As a matter of good practice, you should limit variables to the lowest scope in which they are needed. If they're only used inside a loop, they should only exist inside that loop.
|
Did not know that. Thought there may be some sort of benefit of declaring the variables only once.
|
Quote:
- Create the variable - Assign memory address to it. - Allocate the memory for it. - Then upvalue it with something. However if you keep it outside the for loop, then the first 3 step is gonna run when you load the addon and only then, not recreating them at each loop, make the for loop run faster, since it only gonna overwrite whatever it can find the assigned memory address. (Quick note with the current memory modules (DDR2-DDR3) overwriting a value is 30% faster then completely clear a memory block clean.) However accessing a variable outside the loop also take some extra time. You don't really make the whole code run faster, however you spread the workload into more modules, making the CPU/Memory peak usage lower. More info in this thread: http://www.wowinterface.com/forums/s...t=47694&page=3 |
Best place for optimising here is
Remove the Lua Code:
If you really want to check if the debuffList exists do that before register the event. And localize the UnitDebuff function outside the SearchAuras function Lua Code:
Not huge things but a small performance boost :D Lua Code:
|
Quote:
Anyway, I got the same results as in your post there, but you forgot the format that people actually use. That is, assigning the values directly instead of declaring the variables separately. Unless I did something wrong, that was a lot faster. (302 vs 546 ms at 100 000 iterations) Edit: Yup. Upvalues are actually significantly slower. Code:
local function func() |
Lua Code:
The lower one is faster by ~4%. |
Yeah, but note that most of the execution time goes into creating the tables there. Seems to account for roughly 90% of the time, making the difference relatively smaller.
|
Quote:
Because if this is true, then whats the point of upvaluing global functions in the main chunk? |
Well, in that case you're accessing variables rather than setting them. Upvalues saves you having to do a global lookup. When you're setting a variable there's "nothing" to lookup, I guess. Not sure what a more technical explanation would be.
|
Upvaluing a function indeed only saves you a global lookup. This is why I generally recommend against blindly upvaluing every global function you call in your addon, and only upvaluing the ones you're calling with extreme frequency, such as inside an OnUpdate script or CLEU handler. For more infrequent calls, the difference is hardly more than theoretical, so it's not worth the extra line of code to upvalue it.
Also, what's true in other Lua environments is not always true in the WoW Lua environment, as Blizzard has done a bit of customization. When in doubt, go benchmark it. |
Quote:
|
Well can't you test that aswell by calling collectgarbage() or collectgarbage("count") and checking for timestamps?
|
I just tried to be funny ;)
|
With garbage collection disabled:
lua Code:
Code:
(Run #1) |
All times are GMT -6. The time now is 04:18 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI