Thread Tools Display Modes
04-27-16, 07:06 PM   #1
suipsyco
A Deviate Faerie Dragon
Join Date: Apr 2016
Posts: 13
basic function help

I have a similar code that functions, so I copied the frame, setscript and registerevent codes from the working addons, yet for somereason the very first print statement wont run on this code, any ideas? The end goal of this addon will be to track the Spirit Shift auras on all members of the raid and show on my screen, the damage build up for each aura.

Code:
local f = CreateFrame("Frame")

f:SetScript("OnEvent", function(...)
	print("Start")
	local group = UnitInRaid("player") --if nil party , if >0 raid
	print("Group")
	local size = GetNumGroupMembers() --nil solo, else party or raid
	print("size")
	local groupType = "none"
	if size == nil then groupType = "solo" 
		elseif (group>0 and size<=5) then groupType = "party" 
		elseif (group>0 and size>5) then groupType = "raid" 
		else print("You done screwed up the groupType")
	end
	print("Check1: "..groupType) --Check
	capList = {}
	if (groupType == "party" or groupType == "raid") then CapList() end
	function CapList()
		for i=1, size do 
			local member = groupType..i local m, _ = GetInventoryItemID(member, INVSLOT_TRINKET1); local n,_ = GetInventoryItemID(member, INVSLOT_TRINKET2)
			if m or n =="124225" then
				table.insert(capList, member)
			end
		end 
	end
	for i in capList do print("Check2: "..i) end
	for i in capList do local n, _, _, _, _, _, _, _, _, _, _, _, _,_,t = UnitBuff(i, "Spirit Shift") print n, t end
end)

f:RegisterEvent("UNIT_AURA");
  Reply With Quote
04-27-16, 10:57 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
It might be working, but that checking for group is very ugly.
Lua Code:
  1. local f = f or CreateFrame("Frame)
  2. f:RegisterEvent("GROUP_ROSTER_UPDATE")
  3.  
  4. f:SetScript("OnEvent", function(...)
  5.    if ... ~= "GROUP_ROSTER_UPDATE" then
  6.        return
  7.    end
  8.    local grouptype = nil -- reset
  9.    if IsInRaid() then
  10.       groupType = "raid"
  11.    elseif IsInGroup()
  12.        groupType = "party"
  13.   else
  14.       groupType = nil
  15.    end
  16. end)
  Reply With Quote
04-27-16, 10:59 PM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
http://wow.gamepedia.com/Handling_events#Lua-specific
  Reply With Quote
04-28-16, 10:18 AM   #4
suipsyco
A Deviate Faerie Dragon
Join Date: Apr 2016
Posts: 13
Thanks, I knew there had to be a better way, but after searching for half an hour I decided to try my own way lol.
  Reply With Quote
04-28-16, 12:06 PM   #5
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("GROUP_ROSTER_UPDATE")
  3.  
  4. f:SetScript("OnEvent", function(self, ...)
  5.     if ... ~= "GROUP_ROSTER_UPDATE" then
  6.         return
  7.     end
  8.     local grouptype = nil -- reset
  9.     if IsInRaid() then
  10.        groupType = "raid"
  11.     elseif IsInGroup()
  12.         groupType = "party"
  13.    else
  14.        groupType = nil
  15.     end
  16. end)

Fixed your code. First argument to the function is the frame itself, if more events are needed down the road.
__________________
  Reply With Quote
04-28-16, 07:14 PM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
D'oh, thanks Munk. That's what I get for drycoding when half (okay, 90%) asleep.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » basic function help


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