Thread Tools Display Modes
10-28-16, 08:53 PM   #1
jaayvazian
A Defias Bandit
Join Date: Oct 2016
Posts: 2
Question Hooking into BonusRollFrame

How would I go about hooking into the BonusRollFrame? Here's what I am using now and it is not working.

Code:
frame = CreateFrame("Frame", nil, BonusRoll);
local _, _, difficulty, _, _, _, _, currentZoneID = GetInstanceInfo();
function frame:OnEvent(event)
	if event == "BONUS_ROLL_STARTED"
		if difficulty == 14
			if settings.NormalRaidCheck == true
				function BonusRollFrame_CloseBonusRoll()
				end
				self:UnregisterEvent(event)
			end
		end
		if difficulty == 15
			if settings.HeroicRaidCheck == true
				function BonusRollFrame_CloseBonusRoll()
				end
				self:UnregisterEvent(event)
			end
		end
	end
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", frame.OnEvent)
Any help would be awesome
  Reply With Quote
10-29-16, 07:09 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
For starters, you're not using proper Lua syntax.
http://lua-users.org/wiki/ControlStructureTutorial
http://lua-users.org/wiki/FunctionsTutorial
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-29-16, 09:41 PM   #3
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
- you are missing then at the end of every if line
- frame needs to be local or unique
- your GetInstanceInfo() line needs to be inside the event function, otherwise those variables won't change
- it looks like you want to call BonusRollFrame_CloseBonusRoll(), but you are creating it
- you are looking for BONUS_ROLL_STARTED, but you didn't register for it
- you probably want this to happen every bonus roll, so why are you unregistering events?
- ADDON_LOADED isn't necessary
- you can skip the function name and just put OnEvent in the SetScript using function() code end
- where is the settings table? is there more to this code?
- you have the right idea here, but hooking BonusRollFrame is not what you are doing and not what you need to do
- finally, where is this code? is this a standalone addon?

Last edited by Kanegasi : 10-29-16 at 09:52 PM.
  Reply With Quote
10-31-16, 08:53 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Also, you should absolutely be using an error display when doing any addon development. Basic syntax mistakes (of which there are many in your code) will throw an error. Scoping mistakes (eg. variables defined in the wrong place) and usage mistakes (eg. trying to do math operations on a string) also throw errors. Logical mistakes may or may not throw an error, depending on the specifics. Error messages tell you exactly where the problem is, and generally also tell you exactly what the problem is.

Once you fix all the "hard" errors (the ones that throw actual errors), you can work on the "soft" errors (the ones that don't) by adding print statements in your code that print out messages in-game as things happen, so you can check that variables are being assigned correctly, that control structures (if/else checks, loops, etc.) are running as expected, etc. to help you figure out what's wrong.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-31-16, 07:30 PM   #5
jaayvazian
A Defias Bandit
Join Date: Oct 2016
Posts: 2
Question

After reading this entire thread, I appreciate all the pointers that you guys have given me. I will post my whole code (minus GUI things)

Code:
--Load events
UIConfig:RegisterEvent("ADDON_LOADED");
UIConfig:RegisterEvent("PLAYER_LOGOUT");
UIConfig:RegisterEvent("PLAYER_ENTERING_WORLD");
UIConfig:RegisterEvent("PLAYER_LOGIN");

local settings = {
	MythicDungeonCheck = nil,
	LFRCheck = nil,
	NormalRaidCheck = nil,
	HeroicRaidCheck = nil,
	MythicRaidCheck = nil
}

UIConfig:SetScript("OnEvent", function(self, event, arg1)
	if event == "ADDON_LOADED" and arg1 == "BonusRollManager" then
		if firstTimeCheck == nil then
			settings.MythicDungeonCheck = false
			settings.LFRCheck = false
			settings.NormalRaidCheck = false
			settings.HeroicRaidCheck = false
			settings.MythicRaidCheck = false
			firstTime = firstTimeCheck
			firstTime = false
			
		else
			settings.MythicDungeonCheck = _G["MythicDungeonCheck"]
			UIConfig.MythicDungeon:SetChecked(settings.MythicDungeonCheck);
			
			settings.LFRCheck = _G["LFRCheck"]
			UIConfig.LFR:SetChecked(settings.LFRCheck);
			
			settings.NormalRaidCheck = _G["NormalRaidCheck"]
			UIConfig.NormalRaidCheck:SetChecked(settings.NormalRaid);
			
			settings.HeroicRaidCheck = _G["HeroicRaidCheck"]
			UIConfig.HeroicRaidCheck:SetChecked(settings.HeroicRaid);
			
			settings.MythicRaidCheck = _G["MythicRaidCheck"];
			UIConfig.MythicRaid:SetCheck(settings.MythicDungeonCheck)
		end
	end
	
	if event == "PLAYER_ENTERING_WORLD"then	
		if firstTimeCheck == nil then
			settings.MythicDungeonCheck = false
			settings.LFRCheck = false
			settings.NormalRaidCheck = false
			settings.HeroicRaidCheck = false
			settings.MythicRaidCheck = false
			firstTime = false		
			firstTime = firstTimeCheck
		else		
			_G["MythicDungeonCheck"] = settings.MythicDungeonCheck
			_G["LFRCheck"] = settings.LFRCheck
			_G["NormalRaidCheck"] = settings.NormalRaidCheck
			_G["HeroicRaidCheck"] = settings.HeroicRaidCheck
			_G["MythicRaidCheck"] = settings.MythicRaidCheck
		end		
	end
end)

UIConfig:SetScript("OnHide",
	function()
		settings.MythicDungeonCheck = UIConfig.MythicDungeon:GetChecked();
		UIConfig.MythicDungeon:SetChecked(settings.MythicDungeonCheck);
		_G["MythicDungeonCheck"] = settings.MythicDungeonCheck		
		
		settings.LFRCheck = UIConfig.LFR:GetChecked();
		UIConfig.LFR:SetChecked(settings.LFRCheck);
		_G["LFRCheck"] = settings.LFRCheck
		
		settings.NormalRaidCheck = UIConfig.NormalRaid:GetChecked();
		UIConfig.NormalRaid:SetChecked(settings.NormalRaidCheck);
		_G["NormalRaidCheck"] = settings.NormalRaidCheck
		
		settings.HeroicRaidCheck = UIConfig.HeroicRaid:GetChecked();
		UIConfig.HeroicRaid:SetChecked(settings.HeroicRaidCheck);
		_G["HeroicRaidCheck"] = settings.HeroicRaidCheck
		
		settings.MythicRaidCheck = UIConfig.MythicRaid:GetChecked();
		UIConfig.MythicRaid:SetChecked(settings.MythicRaidCheck);
		_G["MythicRaidCheck"] = settings.MythicRaidCheck
	
	end
);

UIConfig:SetScript("OnShow",
	function()
		settings.MythicDungeonCheck = UIConfig.MythicDungeon:GetChecked();
		UIConfig.MythicDungeon:SetChecked(_G["MythicDungeonCheck"]);
		
		settings.LFRCheck = UIConfig.LFR:GetChecked();
		UIConfig.LFR:SetChecked(_G["LFRCheck"]);
		
		settings.NormalRaidCheck = UIConfig.NormalRaid:GetChecked();
		UIConfig.NormalRaid:SetChecked(_G["NormalRaidCheck"]);
		
		settings.HeroicRaidCheck = UIConfig.HeroicRaid:GetChecked();
		UIConfig.HeroicRaid:SetChecked(_G["HeroicRaidCheck"]);
		
		settings.MythicRaidCheck = UIConfig.MythicRaid:GetChecked();
		UIConfig.MythicRaid:SetChecked(_G["MythicRaidCheck"]);	
	end
);

--Slash Ccommand
SLASH_BRM1, SLASH_BRM2 = '/brm', '/rm'; -- 3.
function SlashCmdList.BRM(msg, editbox) -- 4.
	UIConfig:Show();
end

local frame = CreateFrame("Frame", nil, BonusRollFrame);
frame:RegisterEvent("ADDON_LOADED")

local function eventHandler(self, event, ...)
BonusRollFrame:SetScript("OnShow", function(self, event, ...)
	local _, _, difficulty, _, _, _, _, currentZoneID = GetInstanceInfo();
		if difficulty == 14 then -- Normal Raid
			if settings.NormalRaidCheck == true then
				BonusRollFrame_CloseBonusRoll()
			end
		elseif difficulty == 15 then -- Heroic Raid 
			if settings.HeroicRaidCheck == true then
				BonusRollFrame_CloseBonusRoll()
			end
		elseif difficulty == 16 then -- Mythic Raid
			if settings.MythicRaidCheck == true then
				BonusRollFrame_CloseBonusRoll()
			end
		elseif difficulty == 17 then -- LFR
			if settings.LFRCheck == true then
				BonusRollFrame_CloseBonusRoll()
			end
		elseif difficulty == 23 then
			if settings.MythicDungeonCheck == true then
				BonusRollFrame_CloseBonusRoll()
			end
		else
			print("Some kind of error.");
		end
	end)
frame:SetScript("OnEvent", frame.OnEvent)

end
edit: It seems to not be working still.

Last edited by jaayvazian : 10-31-16 at 07:31 PM. Reason: line
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Hooking into BonusRollFrame


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