08-06-09, 05:22 AM | #1 |
Simple button help needed
Hello
I am completly new to modding and coding, and I need some very simple help regarding some buttons and a single slash command. This is my first mod, and the purpose of it is simply to create a little frame in game which is shown/hidden when typing /innu Now, none of my coding seems to work, since neither the slash command nor the buttons work at all. My elements are called: InnuFrame (which is the frame all my buttons are on) CloseInnu (the button that closes the menu when clicked on) InnuExitGame (Exits the game) InnuLogout (logs out) InnuGoDND (types /dnd in game) InnuGoAFK (types /afk in game) InnuToggleHelm (toggles whether the helm is shown or not) InnuToggleCloak (toggles whether the cloak is shown or not) InnuMuteVolume (sets master volume to 100%) InnuUnmuteVolume (set master volume to 0%) Now, I know my code is completly wrong, but here it is: Code:
SLASH_INNU1 = "/innu" SlashCmdList["INNU"] = InnuFrame function InnuFrame if (InnuFrame:Show) then InnuFrame:Hide else if (InnuFrame:Hide) InnuFrame:Show end end end function CloseInnu_OnClick() InnuFrame:Hide end function InnuExitGame_OnClick() Quit end function InnuLogout_OnClick() Logout end function InnuGoDND_OnClick() /dnd end function InnuGoAFK_OnClick() /afk end function InnuToggleCloak_OnClick() ShowCloak end function InnuToggleHelm_OnClick() ShowHelm end function InnuUnmuteVolume_OnClick() set MasterVolume 100 end function InnuMuteVolume_OnClick() set MasterVolume 0 end Thanks loads loads loads loads loads in advance, I really appreciate it Last edited by Faelara : 08-06-09 at 05:26 AM. |
|
08-06-09, 01:06 PM | #2 |
Ima take a stab at this just to see if what I have learned here recently is of any real use.
Code:
local innuframestate = 0 SLASH_INNU1 = "/innu" SlashCmdList["INNU"] = function(msg) UpdateInnuFrame() end function UpdateInnuFrame() if (innuframestate == 0) then innuframe:Show() innuframestate = 1 elseif (innuframestate == 1) then innuframe:Hide() innuframestate =0 else end and then just use the function UpdateInnuFrame() with any thing you wish. NOTE*** Just trying to apply what I have learned as having BEEN as beginner as you not all that long ago. Also all of the above is an attempt from memory so PLEASE correct my syntax so it is correct. There is prolly a more complex way of doing this. But this is how I would do it with the basics of it all.
__________________
...because I can... THAT'S why... |
|
08-06-09, 01:47 PM | #3 |
First of all to have a frame show, you need to create one...
Code:
InnuFrame = CreateFrame("Frame", InnuFrame, WorldFrame) InnuFrame:SetWidth(300) InnuFrame:SetHeight(300) InnuFrame:SetBackdrop(StaticPopup1:GetBackdrop()) InnuFrame:Show() (Change this to Hide() when you are done so it will hide when the player loads. Right now it will show) InnuFrame:SetFrameStrata("HIGH") InnuFrame:SetClampedToScreen(true) InnuFrame:SetMovable(true) InnuFrame:EnableMouse(true) InnuFrame:SetScript("OnMouseDown",function() InnuFrame:StartMoving() end) InnuFrame:SetScript("OnMouseUp",function() InnuFrame:StopMovingOrSizing() end) Now, if you want to show the frame on slash command, you must do it like this... Code:
SLASH_Innu1 = "/innu" SlashCmdList["InnuFrame"] = InnuFrame_SlashCommandHandler(); function InnuFrame_SlashCommandHandler(arg1) if(arg1 == "innuframe") then if(InnuFrame:IsShown()) then InnuFrame:Hide() else InnuFrame:Show() end end Code:
InnuFrame.btn = CreateFrame("BUTTON", nil, InnuFrame, "UIPanelButtonTemplate") InnuFrame.btn:SetWidth(100) InnuFrame.btn:SetHeight(22) InnuFrame.btn:SetPoint("TOP", InnuFrame, "TOP", -75,-64) InnuFrame.btn:SetText("Something") InnuFrame.btn:SetPoint("CENTER", InnuFrame, "CENTER") InnuFrame.btn:SetScript("OnClick", function() print("hello") end) InnuFrame.btn:SetAlpha(1) InnuFrame.btn:Show() take out print and lets create something for say...get afk status then Code:
InnuFrame.btn:SetScript("OnClick", function() if UnitIsAFK("player") then print:AddMessage("You are AFK") end end) Code:
InnuFrame.btnexit = CreateFrame("BUTTON", nil, InnuFrame, "UIPanelButtonTemplate") InnuFrame.btnexit:SetWidth(20) InnuFrame.btnexit:SetHeight(20) InnuFrame.btnexit:SetPoint("TOP", InnuFrame, "TOP", 125,-10) InnuFrame.btnexit:SetText("X") InnuFrame.btnexit:SetPoint("CENTER", InnuFrame, "CENTER") InnuFrame.btnexit:SetScript("OnClick", function() InnuFrame:Hide() end end) InnuFrame.btnexit:SetAlpha(1) InnuFrame.btnexit:Show() Btw this is dry code so not going to say it will work off the bat. Hope this helps. Last edited by Soulofsin_007 : 08-06-09 at 02:05 PM. |
|
08-06-09, 04:00 PM | #4 |
I read his post as though he knew how to create the frame and only needed to know how to hide/show it.
Oh well.. Points for effort?
__________________
...because I can... THAT'S why... |
|
08-06-09, 04:30 PM | #5 |
Well, Faelara posted the code, how can you hide or show a frame that is not created?
Last edited by Soulofsin_007 : 08-06-09 at 04:33 PM. |
|
08-06-09, 05:07 PM | #6 |
Hi.
Thanks for all of your answers, they were all very informative and I believe I've taken this a step further now However, my buttons does still not work, and neither does the /innu command. My addon basically looks like this in game: I want to notice that I've already created and designed the frame and the buttons in WoWAddonStudio, and then copypasted the code into my XML file. This is my new lua code: Code:
InnuFrame = CreateFrame("Frame", InnuFrame, WorldFrame) InnuFrame:SetWidth(236) InnuFrame:SetHeight(170) InnuFrame:SetBackdrop(StaticPopup1:GetBackdrop()) InnuFrame:Hide() InnuFrame:SetFrameStrata("HIGH") InnuFrame:SetClampedToScreen(true) InnuFrame:SetMovable(true) InnuFrame:EnableMouse(true) InnuFrame:SetResizable(true) InnuFrame:SetScript("OnMouseDown",function() InnuFrame:StartMoving() end) InnuFrame:SetScript("OnMouseUp",function() InnuFrame:StopMovingOrSizing() end) local innuframestate = 0 SLASH_INNU1 = "/innu" SlashCmdList["INNU"] = function(msg) UpdateInnuFrame() end function UpdateInnuFrame() if (innuframestate == 0) then innuframe:Show() innuframestate = 1 elseif (innuframestate == 1) then innuframe:Hide() innuframestate =0 else end BINDING_HEADER_INNU = NUM6["Innu"] CloseInnu:SetScript("OnClick", CloseInnu_OnClick) function CloseInnu_OnClick() InnuFrame:Hide() end InnuExitGame:SetScript("OnClick", InnuExitGame_OnClick) function InnuExitGame_OnClick() Quit() end InnuLogout:SetScript("OnClick", InnuLogout_OnClick) function InnuLogout_OnClick() Logout() end InnuGoDND:SetScript("OnClick", InnuGoDND_OnClick) function InnuGoDND_OnClick() /dnd() end InnuGoAFK:SetScript("OnClick", InnuGoAFK_OnClick) function InnuGoAFK() /afk() end InnuToggleCloak:SetScript("OnClick", InnuToggleCloak_OnClick) function InnuToggleCloak_OnClick() ShowCloak() end InnuToggleHelm:SetScript("OnClick", InnuToggleHelm_OnClick) function InnuToggleHelm_OnClick() ShowHelm() end InnuUnmuteVolume:SetScript("OnClick", InnuUnmuteVolume_OnClick) function InnuUnmuteVolume_OnClick() set C end InnuMuteVolume:SetScript("OnClick", InnuMuteVolume_OnClick) function InnuMuteVolume_OnClick() set MasterVolume 0() end Thanks loads loads loads loads in advance. |
|
08-06-09, 05:15 PM | #7 |
1. UpdateInnuFrame() is missing its closing "end"
2. If you're in the top level of the .lua file, functions need to be defined *above* the part where they're passed to SetScript(), so for example this: Code:
CloseInnu:SetScript("OnClick", CloseInnu_OnClick) function CloseInnu_OnClick() InnuFrame:Hide() end Code:
function CloseInnu_OnClick() InnuFrame:Hide() end CloseInnu:SetScript("OnClick", CloseInnu_OnClick) I'm not sure what "set C" is supposed to mean, the problem with "set MasterVolume 0()" should be obvious, you can't put slash commands in a .lua file like this: Code:
function InnuGoAFK() /afk() end Code:
function InnuGoAFK() SendChatMessage("I'm an AFK message.", "AFK") end |
|
08-06-09, 05:40 PM | #8 |
Hi.
Thanks for your answer, I believe I've taken yet another step towards this mod actually working It does still not work though, and I've obviously done a few mistakes again. Code:
BINDING_HEADER_INNU = NUM6["Innu"] InnuFrame = CreateFrame("Frame", InnuFrame, WorldFrame) InnuFrame:SetWidth(236) InnuFrame:SetHeight(170) InnuFrame:SetBackdrop(StaticPopup1:GetBackdrop()) InnuFrame:Hide() InnuFrame:SetFrameStrata("HIGH") InnuFrame:SetClampedToScreen(true) InnuFrame:SetMovable(true) InnuFrame:EnableMouse(true) InnuFrame:SetResizable(true) InnuFrame:SetScript("OnMouseDown",function() InnuFrame:StartMoving() end) InnuFrame:SetScript("OnMouseUp",function() InnuFrame:StopMovingOrSizing() end) local innuframestate = 0 SLASH_INNU1 = "/innu" SlashCmdList["INNU"] = function(msg) UpdateInnuFrame() end function UpdateInnuFrame() if (innuframestate == 0) then innuframe:Show() innuframestate = 1 elseif (innuframestate == 1) then innuframe:Hide() innuframestate =0 else end end function CloseInnu_OnClick() InnuFrame:Hide() end CloseInnu:SetScript("OnClick", CloseInnu_OnClick) function InnuExitGame_OnClick() Quit() end InnuExitGame:SetScript("OnClick", InnuExitGame_OnClick) function InnuLogout_OnClick() Logout() end InnuLogout:SetScript("OnClick", InnuLogout_OnClick) function InnuGoDND() SendChatMessage("DND", "DND") end InnuGoDND:SetScript("OnClick", InnuGoDND_OnClick) function InnuGoAFK() SendChatMessage("AFK", "AFK") end InnuGoAFK:SetScript("OnClick", InnuGoAFK_OnClick) function InnuToggleCloak_OnClick() ShowCloak() end InnuToggleCloak:SetScript("OnClick", InnuToggleCloak_OnClick) function InnuToggleHelm_OnClick() ShowHelm() end InnuToggleHelm:SetScript("OnClick", InnuToggleHelm_OnClick) function InnuUnmuteVolume_OnClick() set Cvar 100 end InnuUnmuteVolume:SetScript("OnClick", InnuUnmuteVolume_OnClick) function InnuMuteVolume_OnClick() set Cvar 0 end InnuMuteVolume:SetScript("OnClick", InnuMuteVolume_OnClick) Thanks for any future answers, help and tips. It is really appreciated and I'm sorry for being a bit dumb at this |
|
08-06-09, 06:58 PM | #9 |
Interesting, I got lua errors when clicking on the buttons with buggrabber disabled.
Message: [string "CloseInnu:OnClick"]:1: attempt to index global 'InnuForm' (a nil value) Time: 08/07/09 02:58:05 Count: 2 Stack: [string "Interface\FrameXML\BasicControls.xml:<Scrip..."]:18: in function <[string "Interface\FrameXML\BasicControls.xml:<Scrip..."]:4> (tail call): ? [C]: ? [string "*:OnClick"]:1: in function <[string "*:OnClick"]:1> Locals: Thanks for all support so far guys, I'ma head to bed now. |
|
08-07-09, 07:07 PM | #10 |
Since InnuForm isn't in your .lua, it must be in another file. You said you had an .xml file also, can you post that? Are there any other files in your addon?
|
|
WoWInterface » Developer Discussions » Lua/XML Help » Simple button help needed |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|