Thread Tools Display Modes
02-28-13, 05:17 PM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Disable event on click?

Hi,

I have a quick question to ask. I am not use to not using KgPanels and I am just trying to make a small addon instead with a .lua file.

This should be very simple. How do I make the Shadowed Unit Frames addon recognisable in my script since it just comes up as nil:

Code:
if ShadowUF.db:GetCurrentProfile() == "ProfileName" then
	BTL:Show()
	TL:Hide()
end
Lua error says:
attempt to index global 'ShadowUF' (a nil value)

Thank you!

_
  Reply With Quote
02-28-13, 05:39 PM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
I don't see exactly how your topic title relates to what you're asking.

Anyhow. What's probably happening is that your addon loads after Shadowed Unit Frames. You need to delay all code with references to ShadowUF until it actually exists. You can do this by registering the ADDON_LOADED event and letting your code run only once the addon parameter is what you need.

For example;

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(self, event, addon)
	if addon ~= "ShadowedUnitFrames" then return end
	self:UnregisterEvent("ADDON_LOADED") -- Once we have the addon we need, we don't need to register anymore

	... -- Your code here
end)
I don't know what the actual addon is called so you'll have to replace that.
  Reply With Quote
02-28-13, 05:51 PM   #3
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Haleth View Post
I don't see exactly how your topic title relates to what you're asking.
Damn I forgot to edit the title, sorry about that. Not sure how that got there!

Thank you so much, I will try that now!
  Reply With Quote
02-28-13, 06:08 PM   #4
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Ok my finished code is there:

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(self, event, addon)
	if addon ~= "ShadowUF" then return end
	self:UnregisterEvent("ADDON_LOADED")
	if ShadowUF.db:GetCurrentProfile() == "MayronUI" then
		BTL:Show()
		TL:Hide()
	else
		TL:Show()
		BTL:Hide()
	end
end)
But unfortunately the:

"BTL:Show()
TL:Hide()"

part never reaches as both of the frames are showing for some reason. I had to also change "ShadowedUnitFrames" to "ShadowUF" because for some reason it came up with a lua error saying that "db" is a nil value but with that instead I do not get any errors. Not sure what that's about. I will keep up the experimenting.
  Reply With Quote
02-28-13, 06:13 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
It's probably being shown after you hide it.
  Reply With Quote
02-28-13, 09:07 PM   #6
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Originally Posted by Mayron View Post
if ShadowUF.db:GetCurrentProfile() == "MayronUI" then
BTL:Show()
TL:Hide()
else
TL:Show()
BTL:Hide()
end
end)
[/code]

But unfortunately the:

"BTL:Show()
TL:Hide()"

part never reaches as both of the frames are showing for some reason. I had to also change "ShadowedUnitFrames" to "ShadowUF" because for some reason it came up with a lua error saying that "db" is a nil value but with that instead I do not get any errors. Not sure what that's about. I will keep up the experimenting.

Hey

Are BTL and TL variables which point to the frames somewhere else in your script? I'm just asking because if you've posted your full script, there's no way that your code is going to know what BTL and TL is.

I'd also consider registering to the "PLAYER_LOGIN" event too, just in-case your addon loads after ShadowedUF. If it does load after ShadowedUF, "ADDON_LOADED" will not catch the event (because it fired before your addon existed).


Lua Code:
  1. local shadowLoaded = false;
  2.  
  3. f:RegisterEvent("ADDON_LOADED");
  4. f:RegisterEvent("PLAYER_LOGIN");
  5.  
  6. f:SetScript("OnEvent", function(self, event, addon)
  7.        
  8.     if ( ( event == "ADDON_LOADED" ) and ( addon == "ShadowUF" ) ) then
  9.         shadowLoaded = true;
  10.     elseif  ( ( event == "PLAYER_LOGIN" ) and IsAddOnLoaded("ShadowUF") ) then
  11.         shadowLoaded = true;
  12.     end
  13.  
  14.     if ( not shadowLoaded ) then return; end
  15.  
  16.     print("ShadowUF has been loaded"); -- temporary to use as a debug tool to ensure that you're code is getting this far.
  17.  
  18.     self:UnregisterEvent("ADDON_LOADED");
  19.     self:UnregisterEvent("PLAYER_LOGIN");
  20.  
  21.     if ShadowUF.db:GetCurrentProfile() == "MayronUI" then
  22.         BTL:Show();
  23.         TL:Hide();
  24.     else
  25.         TL:Show();
  26.         BTL:Hide();
  27.     end
  28.  
  29. end)

Right enough, an easier way would be to simply add ShadowUF as a dependency in your TOC file if your code is pointless without ShadowUF (or an optional dependency if you'd still like your code to run even if ShadowUF has been disabled). The game will then try to ensure that ShadowUF is loaded prior to your addon which will remove some of the guesswork.

Using print() like the example above is a pretty handy way of working out where you're going wrong although I suspect that in the above example, if ShadowUF is loaded early on in the addon loading process, it might not print to chat even if your func does reach that line of code... but it's worth trying.

Aanson
__________________
__________________

Last edited by Aanson : 02-28-13 at 09:41 PM.
  Reply With Quote
03-01-13, 01:12 PM   #7
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Aanson View Post
Hey

Are BTL and TL variables which point to the frames somewhere else in your script? I'm just asking because if you've posted your full script, there's no way that your code is going to know what BTL and TL is.
Thank you for helping but that script (even though no errors came up) did not work.

I can most the entire script the project I'm working on if that helps. Basically I want to expand on my Setup addon so that you click the install button and it uses a reflux command to change everything to "MayronUI" profile and reloads the UI. After that I need a script that if any of the addons are set to "MayronUI" profile then it hides the Setup box art with the install buttons etc and displays this new box:



Here you can enable some "bonus features" which do the following things in the annotation on the image above. I wanted to make this because its complicated for users to have to follow long steps of moving hte chat box with other addons after installing the UI so I wanted to make it easier. So far so good but the main issue is that the script does not recognise the addons loading and I really do not know what to do about it.

Your welcome to see what I've done so far and if I have done other things wrong and the work is too much then I understand.

The Addon file is here:
http://www.mediafire.com/?awc6e990yvz227y
  Reply With Quote
03-01-13, 04:55 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I didn't look at your code, but I'd use the PLAYER_LOGIN event -- so that all non-LoD addons are loaded by the time it fires and, assuming they're using AceAddon's OnInitialize, have loaded and set up their profiles -- in conjunction with a saved variable for your addon; in this (fairly loose) example I've used the saved variable name MUI_INSTALLED.

Code:
local addons = {
	-- Global names of addon objects go here:
	"ShadowUF",
	"OtherAddon",
	"AnotherAddon",
}

local setupMode = "setup"

frame:SetScript("OnEvent", function(self, event, ...)
	if event == "PLAYER_LOGIN" then
		if MUI_INSTALLED then
			setupMode = nil
			-- Nothing to do. Turn everything off.
			return
		end

		for _, addon in pairs(addons) do
			if _G[addon].db:GetCurrentProfile() == "MayronUI" then
				setupMode = "bonus"
				break
			end
		end
		
		if setupMode == "setup" then
			-- Show initial setup window
		elseif setupMode == "bonus" then
			-- Show bonus setup window
		end
	end
end)

SetupExitButton:SetScript("OnClick", function(self)
	-- Do all the setup stuff
	ReloadUI()
end)

BonusExitButton:SetScript("OnClick", function(self)
	local reload
	if EnableChat:IsChecked() then -- asumes this is a CheckButton, not just a Button
		-- Setup bottom left chat box
		reload = true
	end
	if DisableClassColors:IsChecked() then
		-- Turn off class colors
		reload = true
	end
	if ClassicMode:IsChecked() then
		-- Setup classic mode
		reload = true
	end
	MUI_INSTALLED = true
	if reload then
		ReloadUI()
	else
		-- Nothing left to do. Turn everything off.
		self:Hide()
	end
end)
__________________
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

WoWInterface » Developer Discussions » Lua/XML Help » Disable event on click?


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