Thread Tools Display Modes
Prev Previous Post   Next Post Next
09-09-12, 11:46 PM   #1
Brusalk
An Aku'mai Servant
 
Brusalk's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 32
A few questions about Lua pattern matching

So in one of my addons I need access to information on how often a DoT/HoT ticks on a unit.

One of the ways I'm experimenting with is pulling the hasted tick time from the tooltip itself on UNIT_AURA event.

My code:

Code:
addEvent(function(self, event, unit)
	for i=1, 40 do
		for _, spellbar in ipairs(ns.spellbars.active) do
			if spellbar.spellConfig.debuff[1] > 0 then -- We have a debuff to look at
				if unit == (type(spellbar.spellConfig.debuff[2]) == "string" and spellbar.spellConfig.debuff[2] or "target") then
					local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff, value1, value2, value3 = UnitDebuff(unit, i)
					if caster == "player" then
						if spellbar.spellConfig.debuff[1] == spellID then -- Ooh, we found it on this spellbar.
							ns.tooltip:SetUnitDebuff(unit, i)
							local scanText = _G["EventHorizonScanTooltipTextLeft2"]:GetText()
							local tickSpeed = tonumber(string.sub(scanText, string.find(scanText, "every ")+6, string.find(scanText, " sec")-1))
								--tonumber returns nil if it can't be converted to a number
							ns:addDebuff(spellbar, duration, tickSpeed)
							
						end
					end	
				end
			end
		end
	end
end,
"UNIT_AURA")
A cursory inspection of wowhead seems to show that all DoTs/HoTs tooltips say "every x.xx sec".
I'm not versed in Lua pattern matching at all and I managed to get the x.xx information using what I have below, but on a non-matching string it returns garbage information. tonumber() luckily returns nil if the number can't be converted, but I'm sure that there's more efficient/robust ways of doing it using pattern matching.

Does anyone know of a pattern which would match only the x.xx portion of the string to make it more efficient? (Or any other changes to my above code to make it more efficient)

Thanks
-Brusalk
Code:
tonumber(string.sub(scanText, string.find(scanText, "every ")+6, string.find(scanText, " sec")-1))
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » A few questions about Lua pattern matching


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