Thread Tools Display Modes
06-15-13, 05:02 AM   #1
ctrlaltdeny
A Murloc Raider
Join Date: Jun 2013
Posts: 9
Problem using slashcmd

Hello, I am trying to work on my custom addon to perform some actions with my custom UI.



I am using reflux in the following code and taking advantage of slashcmd to cause the reflux profile to shift when a character is logged on. Here is the code I am using (very noobish probably).

Code:
--disable the social button on chat button bar	
FriendsMicroButton:Hide()

--disable the default error frame
UIErrorsFrame:UnregisterEvent"UI_ERROR_MESSAGE"

local frame = CreateFrame("FRAME", "RunOnLoadFrame");
frame:RegisterEvent("PLAYER_LOGIN");
local function eventHandler(self, event, ...)
 
SexyMap2DB[UnitName("player").."-"..GetRealmName()] = "global";
SlashCmdList["REFLUX"]("switch default");
Recount.ConfigWindow:Hide()
 
end
frame:SetScript("OnEvent", eventHandler);
However when using the slash command I get "Interface action failed because of an AddOn", I know its reflux not being able to call protected function of reloadui. Ingame I get a prompt when I see the UI asking me to reload gui to see profile changes. So it does work as intended. Just the error in chat that I would prefer not to have.

Is there an adjustment to this code that can be made to resolve this issue?

Thanks!
  Reply With Quote
06-15-13, 11:45 AM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by ctrlaltdeny View Post
Ingame I get a prompt when I see the UI asking me to reload gui to see profile changes. So it does work as intended.
I'm not sure what you mean by this, but... When you type out the slash command yourself, the ReloadUI is coming from a hardware event - you pressing 'enter' to execute the slash command. Other addons that automate Reflux's setup have a button for users to press - this is also a hardware event. Your addon is trying to do it automatically for the user. This is not using a hardware event for ReloadUI().


In other news...
Lua Code:
  1. --disable the default error frame
  2. UIErrorsFrame:UnregisterEvent"UI_ERROR_MESSAGE"
Please don't. This is overkill and hides helpful messages. Do you users even know this is in there? Get ErrorMonster or something instead.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
06-15-13, 03:33 PM   #3
ctrlaltdeny
A Murloc Raider
Join Date: Jun 2013
Posts: 9
Originally Posted by Seerah View Post
I'm not sure what you mean by this, but... When you type out the slash command yourself, the ReloadUI is coming from a hardware event - you pressing 'enter' to execute the slash command. Other addons that automate Reflux's setup have a button for users to press - this is also a hardware event. Your addon is trying to do it automatically for the user. This is not using a hardware event for ReloadUI().
Thank you, that makes sense, I just don't understand why it would produce an error even though Reflux asks me to click a button to reload the UI. Probably a backup incase Wow cannot reload UI normally?

Originally Posted by Seerah View Post
In other news...
Lua Code:
  1. --disable the default error frame
  2. UIErrorsFrame:UnregisterEvent"UI_ERROR_MESSAGE"
Please don't. This is overkill and hides helpful messages. Do you users even know this is in there? Get ErrorMonster or something instead.
That is only turned off by preference, its not something I put in to prevent errors showing in chat, I just dislike being spammed by cannot use this spell, spell not ready etc and a lot of others dislike that also.

When I create a toon I get most settings correct however sexymap does not seem to want to have global profile set by default even when saved via reflux, and recount also has issues (hence the code to hide the config window).

What I see when I join is simply a prompt asking to reload UI, and that error in chat regarding interface action. Are you essentially saying there is no way I can have my defaults set up automatically without actually typing/pressing something without having errors showing in chat due to protected command of ReloadUI?

There are no workarounds?

PS: I currently have no users, this is a work in progress, I like to think it looks pretty decent to be honest, it just requires a lot of fine tuning.

Last edited by ctrlaltdeny : 06-15-13 at 03:35 PM.
  Reply With Quote
06-15-13, 04:01 PM   #4
Vis
A Pyroguard Emberseer
 
Vis's Avatar
Join Date: Mar 2009
Posts: 1,827
You may want to take a look at how nibProfileLoader works. It's designed for being able to almost auto load the right profile. A hardware event, ie clicking a box, is still required though.
  Reply With Quote
06-15-13, 04:31 PM   #5
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by ctrlaltdeny View Post
Are you essentially saying there is no way I can have my defaults set up automatically without actually typing/pressing something without having errors showing in chat due to protected command of ReloadUI?

There are no workarounds?
Nope, no workarounds. A reload requires a hardware action. Otherwise people could end up in infinite reload loops >.>
  Reply With Quote
06-15-13, 05:32 PM   #6
ctrlaltdeny
A Murloc Raider
Join Date: Jun 2013
Posts: 9
Fair enough guys, are there any tutorials to have a frame open with text and an image, and the button press itself activate the profile change?

I will create a blank profile with no interface, and just have that dialog come up with the press to activate the proper profile. Probably the cleanest way without it looking sloppy that I can do it.

Thanks!
  Reply With Quote
06-15-13, 06:49 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by ctrlaltdeny View Post
That is only turned off by preference, its not something I put in to prevent errors showing in chat, I just dislike being spammed by cannot use this spell, spell not ready etc and a lot of others dislike that also.
I know very well what that code does and what you attempt to do with it.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
06-15-13, 08:00 PM   #8
ctrlaltdeny
A Murloc Raider
Join Date: Jun 2013
Posts: 9
Ok, so...

What would be the best way of establishing the below logic in Lua.

On load of a character via PLAYER_LOGIN event
Check if character is first load, if it is do X.
If it has already been run before, do Y.

For example, as a really basic install UI (most likely with a dialog box that I can use to implement a reflux profile switch).

Thanks!
  Reply With Quote
06-15-13, 08:04 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
TOC:
Code:
## SavedVariablesPerCharacter: MyUILoaded
Lua:
Code:
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self, event, ...)
    if MyUILoaded then
        -- This character has already loaded your UI.
        -- do Y
    else
        -- This character has never loaded your UI before.
        MyUILoaded = true
        -- do X
    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
06-15-13, 09:12 PM   #10
ctrlaltdeny
A Murloc Raider
Join Date: Jun 2013
Posts: 9
Thanks for the reply guys, even though one of you removed their post, but I got it copied down. Any reason you removed your post?

Thanks Phanx, thats almost elegant in its programming.

So just for my own understanding.

We are setting variables for the addon and checking for it when its run on player login. If the saved variable is there, nothing needs to be done because it exists (and is thus installed). Else it will run my install code. That about right?

I will try and put the two codings together to form my install addon.

Thanks to you both!
  Reply With Quote
06-15-13, 09:14 PM   #11
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by ctrlaltdeny View Post
Thanks for the reply guys, even though one of you removed their post, but I got it copied down. Any reason you removed your post?
I was working on making it a bit neater / easier to read then got sidetracked for a bit with my own UI bugs If you got it copied down and it's legible then that's good
  Reply With Quote
06-15-13, 09:21 PM   #12
ctrlaltdeny
A Murloc Raider
Join Date: Jun 2013
Posts: 9
Thanks, I wondered.

I'm not a complete beginner to syntax, I've tinkered with HTML, CSS, and some PHP, so I get the basic logic of it (when its fairly basic) but the advanced stuff I would struggle with at first. I learn quickly!

PS: What do you think of the layout/design from the screenshot? Any comments? Feedback appreciated, obviously its a WIP.

Lazy link: KefUI - WIP v0.1
  Reply With Quote
06-15-13, 11:33 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by ctrlaltdeny View Post
We are setting variables for the addon and checking for it when its run on player login. If the saved variable is there, nothing needs to be done because it exists (and is thus installed). Else it will run my install code. That about right?
Yes, except you forgot the part where if it doesn't exist, you set it to "true" so that it does exist next time you log in.

Originally Posted by ctrlaltdeny View Post
PS: What do you think of the layout/design from the screenshot? Any comments? Feedback appreciated, obviously its a WIP.
Alignment is inconsistent, especially with elements near screen edges. Try to line up the edges of nearby elements, and get consistent amounts of space between elements along the right edge of the screen, and those along the bottom edge of the screen.

The gigantic micro menu bar top and center seems like a big waste of space. All those things should be keybound or, if you really like clicking things, the micro menu bar should be smaller, off to the side, and hidden until moused over.

I don't like the transparent background on the character frame stats panel (or other UI panels with text) as it makes it too hard to read the text.

Conversely, the chat frame background feels too big and heavy, and the small increase in readability (vs. no background) isn't worth the bulk.

The inner shadow on the minimap is too dark; I'd get rid of it entirely.

Too many action buttons visible. I have just 6 visible action buttons on all of my characters. Try using more modifier keys to condense actions into fewer buttons, and/or OPie to move less frequently-used actions onto popup action rings (for example, on my shaman, all my totems are on a ring that pops up when I middle-click anywhere on the game world; I just move the cursor toward the totem I want to cast and release the mouse button to cast it and hide the ring).

Portrait in the middle of the unit frame is unnecessary and distracting, making it harder to see the actually useful information.

Unit frame text is overly verbose. X/100 for power text isn't useful -- your maximum power is always the same, and you only need to know how much power you have in order to choose which abilities to use.
__________________
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.

Last edited by Phanx : 06-15-13 at 11:58 PM.
  Reply With Quote
06-16-13, 05:02 AM   #14
ctrlaltdeny
A Murloc Raider
Join Date: Jun 2013
Posts: 9
Thanks for taking the time Phanx,

I will certainly take what you have said on board, however I mostly like the look of the frames, maybe a slight increase towards normal opacity is warranted in some areas I do agree it can be hard to see. I agree with the edge distances.

The inner shadow was more for effect of the edge than anything else, and tbh, the amount of space on the edge that is taken by it is almost nothing so players imo won't lose much at all by having it there.

The micro menu in my first version of this UI was in the same place and was hidden until mouseover, that should be a choice for that person so they know where it is the first time they use my UI.

With the unit frames, I agree partially with the verbose text argument, however the portrait causes no distraction, the only thing I tend to look at is for example on this toon the bar at the bottom that acts as a focus/energy bar. People only need to absorb the info they want. And since this is essentially an addon pack with a theme, I can adjust some aspects but not willing to butcher other peoples work too much.

Thanks again for the feedback, I will certainly take some of it onboard
  Reply With Quote
06-16-13, 07:28 AM   #15
ctrlaltdeny
A Murloc Raider
Join Date: Jun 2013
Posts: 9
Ok, so after some tinkering I have arrived at this code, and it works fine!

RunOnLoad.toc
Code:
## Title: RunOnLoad
## Interface: 50300
## Notes: Hide parts of the UI and runs commands on startup.
## Author: CtrlAltDeny
## X-eMail: [email protected]
## Version: 0.1
## SavedVariablesPerCharacter: IsUILoaded
## Dependencies: Reflux
RunOnLoad.lua
RunOnLoad.lua
Code:
local ProfileName = "default"
local InterfaceName  = "KefUI"


-- Install UI
local function CharAnswered(ans)
     
IsUILoaded = true		 
	 
    if ans then
        local RefluxArg = string.format("%s %s", "switch", ProfileName)
        SlashCmdList.REFLUX(RefluxArg) -- This will cause a UI reload
	else 	
	    SendChatMessage("You can\'t install my UI if you don't say Yes!!");
	IsUILoaded = false	
    end
end
  
-- Ask the player if he wishes to install
local function AskNewChar()
    StaticPopupDialogs["NewChar"] = {
        text = "New character detected! Do you wish to load the settings for %s?",
        button1 = "Yes",
        button2 = "No",
 
        timeout = 0,
        whileDead = true,
        hideOnEscape = false,
        notClosableByLogout = true,
 
        OnAccept = function()
            CharAnswered(true)
			end,
        
         OnCancel = function()
            CharAnswered(false)
        end,
    }
StaticPopup_Show ("NewChar", InterfaceName);
	end
 
 --Perform check if UI has been loaded
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self, event, ...)
    if IsUILoaded then
        
		-- This character has already loaded your UI.
        SendChatMessage("UI has already been installed...");
    
	else
        -- This character has NEVER loaded your UI before.
    		
        SendChatMessage("UI needs to be installed...");
		AskNewChar();
		end
end)
Any issues with this code? I did kinda just combine the two, hope I did it well, it works anyways lol, with no errors!

Last edited by ctrlaltdeny : 06-16-13 at 07:40 AM. Reason: Added some error correction to the prompt to install.
  Reply With Quote
06-16-13, 06:35 PM   #16
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
A couple issues:

1. IsUILoaded is unacceptable as a global variable name. It's overly generic, and likely to conflict with other addons or the Blizzard UI, especially in cases of accidental leakage. The names of your saved variables should always include your addon name, or a unique abbreviation of your addon name.

2. Similarly, NewChar is not a good StaticPopup name. You should choose a name that's unique and includes your addon name.

2. SendChatMessage does exactly what it says -- it sends a chat message. If you don't specify a channel, it defaults to "SAY", so your code is basically doing "/say UI has already been installed..." and anyone standing near the user's character will see that message. You should use DEFAULT_CHAT_FRAME:AddMessage instead of SendChatMessage -- but I would strongly recommend against spamming the user's chat frame every time they log in with a message telling them they already installed your UI. Unless they're the guy from Memento, they already know.

3. Similarly, there's no need to spam the user with a chat frame message telling them to install the UI when you're also popping up a dialog box telling them to install the UI. The dialog box -- the thing they actually have to interact with -- is sufficient.

4. Finally, your code would be a lot more readable if you used indentation consistently.

Here's a more straightforward version with unique global variables, and without all the unnecessary functions and variables. The SavedVariable name has been changed to "KefUI_Installed".

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self, event, ...)
	self:UnregisterEvent(event)
	self:SetScript("OnEvent", nil)
	if not KefUI_Installed then
		StaticPopupDialogs["KefUI_Install"] = {
			text = "New character detected! Do you wish to load the settings for KefUI?",
			button1 = "Yes",
			button2 = "No",

			timeout = 0,
			whileDead = true,
			hideOnEscape = false,

			OnAccept = function()
				KefUI_Installed = true
				SlashCmdList.REFLUX("switch default")
			end,
		}
		StaticPopup_Show("KefUI_Install")
	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
06-17-13, 02:12 AM   #17
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
If I may suggest a very minor change to Phanx's code for the purposes of localization...
Lua Code:
  1. local KefUI, L = ...
  2. local locale = GetLocale()
  3.  
  4. if locale == "deDE" then
  5.     L["New character detected! Do you wish to load the settings for KefUI?"] = ""
  6. elseif locale == "itIT" then L["New character detected! Do you wish to load the settings for KefUI?"] = ""
  7.     -- etc etc through locales, except "enUS"
  8. else  -- default, or "enUS"
  9.     L["New character detected! Do you wish to load the settings for KefUI?"] = "New character detected! Do you wish to load the settings for KefUI?"
  10. end
  11.  
  12. local f = CreateFrame("Frame")
  13. f:RegisterEvent("PLAYER_LOGIN")
  14. f:SetScript("OnEvent", function(self, event, ...)
  15.     self:UnregisterEvent(event)
  16.     self:SetScript("OnEvent", nil)
  17.     if not KefUI_Installed then
  18.         StaticPopupDialogs["KefUI_Install"] = {
  19.             text = L["New character detected! Do you wish to load the settings for KefUI?"],
  20.             button1 = YES, -- use global strings, which are pre-translated
  21.             button2 = NO,
  22.  
  23.             timeout = 0,
  24.             whileDead = true,
  25.             hideOnEscape = false,
  26.  
  27.             OnAccept = function()
  28.                 KefUI_Installed = true
  29.                 SlashCmdList.REFLUX("switch default")
  30.             end,
  31.         }
  32.         StaticPopup_Show("KefUI_Install")
  33.     end
  34. end)
  Reply With Quote
06-17-13, 03:40 AM   #18
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Localization is a good idea, but the way you did it will result in German and Italian users getting a popup dialog with no text.

Also, a shorter key would be better for readability.

Code:
local KefUI, L = ...
L.DialogText = "New character detected! Do you wish to load the settings for KefUI?"

local locale = GetLocale()
if locale == "esES" or locale == "esMX" then
    L.DialogText = "Nuevo personaje detecta! ¿Desea cargar la configuración de KefUI?"
-- add elseif conditions for other locales here when you get translations for them
end

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self, event, ...)
    self:UnregisterEvent(event)
    self:SetScript("OnEvent", nil)
    if not KefUI_Installed then
        StaticPopupDialogs["KefUI_Install"] = {
            text = L.DialogText,
            button1 = YES, -- use global strings, which are pre-translated
            button2 = NO,
 
            timeout = 0,
            whileDead = true,
            hideOnEscape = false,
 
            OnAccept = function()
                KefUI_Installed = true
                SlashCmdList.REFLUX("switch default")
            end,
        }
        StaticPopup_Show("KefUI_Install")
    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 » Problem using slashcmd


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