WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Hide on Load Plus Minimap button actions. (https://www.wowinterface.com/forums/showthread.php?t=45805)

Doxramos 02-08-13 05:14 PM

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. :)

Haleth 02-08-13 05:52 PM

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)


Doxramos 02-08-13 06:26 PM

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


Haleth 02-08-13 07:37 PM

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.

Phanx 02-08-13 11:35 PM

Quote:

Originally Posted by Doxramos (Post 272873)
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.


All times are GMT -6. The time now is 03:38 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI