Thread Tools Display Modes
07-17-10, 01:20 PM   #1
magges
An Aku'mai Servant
 
magges's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 36
Create Toggle function

Hey there is it possible to create a Toggle function but NOT like this:

if blabla:IsShown() then
blabla Hide()


I wanna toggle between
WIM.HideAllWindows()
WIM.ShowAllWindows()

so i have to create a function that says .. on the first click = WIM.HideAllWindows(), on the second click = WIM.ShowAllWindows() .. and then back to the first.
Is something like this possible?

thanks
magges
  Reply With Quote
07-17-10, 01:26 PM   #2
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
Code:
local hidden -- outside of function to preserve variable

function toggleWindows()
    if hidden then
        WIM.ShowAllWindows()
    else
        WIM.HideAllWindows()
    end
    hidden = not hidden -- toggles the flag
end
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
07-17-10, 01:52 PM   #3
magges
An Aku'mai Servant
 
magges's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 36
Omg >.<
Thanks .. now i can delete my 200+ Lines of a menu ..cause this works fine ^^
thanks
  Reply With Quote
07-17-10, 07:18 PM   #4
magges
An Aku'mai Servant
 
magges's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 36
Ive another Question.

If i wanna toggle e.g. Tetris (http://www.wowinterface.com/download...11-Tetris.html) but he didnt set a name for the Frames

Code:
local mainWnd = CreateFrame("frame", nil, UIParent)
So how can i toggle it .. mainWnd or Tetris.mainWnd always is a 'nil value' :/

magges

/e or i dont rly need to toggle it. Just show up
-- slash command
SLASH_TETRIS1 = "/tetris"
SLASH_TETRIS2 = "/tt"
SlashCmdList["TETRIS"] = function (msg)
gamePane:SetScript("OnUpdate", UpdatePane)
mainWnd:Show()
end
in tetris.lua

Last edited by magges : 07-17-10 at 07:24 PM.
  Reply With Quote
07-17-10, 08:33 PM   #5
Elhana
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 51
local mainWnd - means only available within that lua file, but if you look at slash command handler:

Code:
SlashCmdList["TETRIS"] = function (msg)
   gamePane:SetScript("OnUpdate", UpdatePane)
   mainWnd:Show()
end
Therefore running: SlashCmdList["TETRIS"]() should do the trick - same as doing /tt or /tetris

You can test it with /script SlashCmdList["TETRIS"]()
  Reply With Quote
07-18-10, 03:51 AM   #6
magges
An Aku'mai Servant
 
magges's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 36
Originally Posted by Elhana View Post
local mainWnd - means only available within that lua file, but if you look at slash command handler:

Code:
SlashCmdList["TETRIS"] = function (msg)
   gamePane:SetScript("OnUpdate", UpdatePane)
   mainWnd:Show()
end
Therefore running: SlashCmdList["TETRIS"]() should do the trick - same as doing /tt or /tetris

You can test it with /script SlashCmdList["TETRIS"]()
Thanks Works great
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Create Toggle function

Thread Tools
Display Modes

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