Thread Tools Display Modes
02-08-13, 05:14 PM   #1
Doxramos
A Defias Bandit
Join Date: Feb 2013
Posts: 2
Hide on Load Plus Minimap button actions.

I'm hoping I can get some help on this. I'm trying to get an addon running. (First time with LUA)
The first thing I have in my LUA is:
Code:
function ServerPanel_OnLoad()
ServerPanel:Hide();
end
Essentially; When I start the client I want the addon to be hidden; afterwards I have my MiniMap Button and it's scripted with
Code:
function ServerCharacters_MinimapButton_OnClick()
	ServerPanel:Hide()
end
The minimap button works, but I want to have it as Show for one, but more along the lines of:
Code:
function ServerCharacters_MinimapButton_OnClick()
if ServerPanel == Show then
ServerPanel:Hide();
elseif
ServerPanel:Show();
end
I dont know if that's right or not, but that's why I'm here asking for help. Thank you.
  Reply With Quote
02-08-13, 05:52 PM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
1) You don't need to write a function for a frame to be hidden by default. Just use ServerPanel:Hide() after creation.

2) That would be:

Code:
local function ServerCharacters_MinimapButton_OnClick()
	ServerPanel:SetShown(not ServerPanel:IsShown())
end
It's also a good idea to make your functions local, like I did there, to avoid polluting the global name space (= adding tons of things other addons can refer to, increasing the possibility of conflicts). If you want your functions to be accessible outside of the lua file you've placed them in, you should use the addon-wide table that each addon has by default. Crude example:

Code:
local _, myAddOnTable = ...
myAddOnTable.MinimapButton_OnClick = function()
	... -- do stuff
end
If you only need to use a function once, then you don't need to assign it to a variable at all. For instance:

Code:
myMinimapButton:SetScript("OnClick", function()
	ServerPanel:SetShown(not ServerPanel:IsShown())
end)
  Reply With Quote
02-08-13, 06:26 PM   #3
Doxramos
A Defias Bandit
Join Date: Feb 2013
Posts: 2
I put
Code:
ServerPanel:Hide();
and
Code:
ServerPanel:Hide()
at the beginning of my LUA and it didn't hide the addon on loadup but instead stopped all functions; afterwards I tried to used the third code to have the same thing happen =/ I'm not getting any LUA errors just all show hides stop working altogether.


Just a thought, but for the if else statement; Shouldn't there be something along the lines of
Code:
function myfunction_OnClick()
if ServerPanel:Hide == true then
ServerPanel:Show();
else
ServerPanel:Hide();
end

Last edited by Doxramos : 02-08-13 at 06:41 PM.
  Reply With Quote
02-08-13, 07:37 PM   #4
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
You can't refer to ServerPanel before the variable is declared. So, add it only after you create your ServerPanel frame. Also, it doesn't matter in lua whether or not you add a semicolon at the end of your line.

What do you mean by 'the third code'? If you mean the third snipped I posted; that was just an example to show that you don't need to declare your function as a variable if you only use it once.

As for the last bit of code you posted; a colon is followed by a method call (which is followed by brackets). Show and Hide also are not used to check whether a frame is shown. To write it the way you have in mind, it'd have to be:

Code:
if ServerPanel:IsShown() then
	ServerPanel:Hide()
else
	ServerPanel:Show()
end
However, it's simpler to use:

Code:
ServerPanel:SetShown(not ServerPanel:IsShown())
Like I posted before.
  Reply With Quote
02-08-13, 11:35 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Doxramos View Post
I put <<code>> at the beginning of my LUA and it didn't hide the addon on loadup but instead stopped all functions; afterwards I tried to used the third code to have the same thing happen =/ I'm not getting any LUA errors just all show hides stop working altogether.
Can you post your whole code? Posting snippets just leads to confusion on both ends.
__________________
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 » General Authoring Discussion » Hide on Load Plus Minimap button actions.


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