Quantcast
How to show XML frame with slash command - WoWInterface
Thread Tools Display Modes
04-16-21, 07:13 AM   #1
nemvokrobot
A Murloc Raider
Join Date: Feb 2021
Posts: 6
How to show XML frame with slash command

Hi

I have an XML frame:

Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
    <Script file="TestFrame.lua"/>
    <Frame name="TestFrame" parent="UIParent" frameStrata="BACKGROUND" hidden="true" setAllPoints="true">
		<Layers>
		</Layers>
        <Scripts>
            <OnLoad>
                self:RegisterEvent("PLAYER_ENTERING_WORLD");
            </OnLoad>
            <OnEvent function="Testframe_OnEvent"/>
	    <OnUpdate function="Testframe_OnUpdate"/>
        </Scripts>
    </Frame>
</Ui>
and I want to show this frame by typing "/showtest" to the chat. I've tried in LUA this way but didn't work:

Code:
local myframe = TestFrame;
SLASH_SHOWTEST1 = "/showtest"
SlashCmdList["SHOWTEST"] = function(message, editbox)
	myframe:Show();
end
any ideas who done something similar? or is it not possible to do it with an XML frame?
  Reply With Quote
04-16-21, 07:57 AM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 565
You haven't provided anything in your code about how the frame should look. No templates or textures. It exists, but it's effectively invisible and it spans the entire length and width of the screen. You can use the following command to prove it exists:

/dump TestFrame
  Reply With Quote
04-16-21, 07:59 AM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,167
I can't speak directly to your question, but I can say that making a globally named frame "TestFrame" is a horrid idea. How do you know there aren't 1000 frames with that same name? Even your slash command has a very bad global name.
  Reply With Quote
04-16-21, 09:14 AM   #4
nemvokrobot
A Murloc Raider
Join Date: Feb 2021
Posts: 6
Originally Posted by Kanegasi View Post
You haven't provided anything in your code about how the frame should look. No templates or textures. It exists, but it's effectively invisible and it spans the entire length and width of the screen. You can use the following command to prove it exists:

/dump TestFrame
I do make a texture for it at event, but I haven't provided its code because it is not important since if I show the frame without slash command it will work, so shouldn't be related at all to visual issues.

Last edited by nemvokrobot : 04-16-21 at 09:39 AM.
  Reply With Quote
04-16-21, 09:17 AM   #5
nemvokrobot
A Murloc Raider
Join Date: Feb 2021
Posts: 6
Originally Posted by myrroddin View Post
I can't speak directly to your question, but I can say that making a globally named frame "TestFrame" is a horrid idea. How do you know there aren't 1000 frames with that same name? Even your slash command has a very bad global name.
This is just for testing purposes, so I don't really care about proper namings sorry.

Last edited by nemvokrobot : 04-16-21 at 09:38 AM.
  Reply With Quote
04-16-21, 09:32 AM   #6
nemvokrobot
A Murloc Raider
Join Date: Feb 2021
Posts: 6
Anyway I did a workaround by making a local variable called ToShow and setting it true at the slash function and then at the frame's Update use Self:Show() if that variable is true. Idk why it didn't work directly lol.

Last edited by nemvokrobot : 04-16-21 at 09:37 AM.
  Reply With Quote
04-16-21, 10:17 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,417
The the name you give a frame is entered into the global table as a reference to that frame. If I remember correctly, the first frame with a given name gets the global table variable.

If you have more than one frame called TestFrame then running TestFrame:SetShown(not TesFrame:IsShown()) will toggle the first TestFrame created which may not be yours or more likely is one of the other 50 TestFrames you've got sitting in long forgotten test code.

Giving unique names to anything created as a global is good advice as you're sharing that space with all other addons including the entire Blizzard default UI.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-16-21, 08:13 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,029
Do you have script errors turned on? Errors earlier in your code can block the rest of it from running.
Run /console scriptErrors 1 to enable. (It's also a good idea to /reload afterward to see any errors you missed in the loading process too)



Keep your ToC load order in mind. Files are loaded one at a time in the order listed in your ToC file. If your XML loads first, it can't access the functions defined for your script handlers in your Lua file. If you load Lua first, the frame defined in the XML won't be loaded yet either.

Let's assume you have your Lua file loaded first as this is easier to work with. Here's the code you posted.
Originally Posted by nemvokrobot View Post
Lua Code:
  1. local myframe = TestFrame;
  2. SLASH_SHOWTEST1 = "/showtest"
  3. SlashCmdList["SHOWTEST"] = function(message, editbox)
  4.     myframe:Show();
  5. end
As I mentioned earlier, when the Lua file is loaded first, TestFrame doesn't exist yet, so myframe gets assigned nil. When you run your slash command, it should throw an "attempt to index nil" error if you had scriptErrors enabled. The best way to fix this is to get rid of the myframe local.
Lua Code:
  1. SLASH_SHOWTEST1 = "/showtest"
  2. SlashCmdList["SHOWTEST"] = function(message, editbox)
  3.     TestFrame:Show();
  4. end
This causes the global TestFrame to resolve when the slash command is run and isn't affected by your ToC load order.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-16-21 at 08:36 PM.
  Reply With Quote
04-16-21, 08:14 PM   #9
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,167
Originally Posted by nemvokrobot View Post
This is just for testing purposes, so I don't really care about proper namings sorry.
That is not an excuse. You should always care about proper names for global variables. To be blunt, if you do not wish to learn, then don't ask for help. And expect your code to fail when you do not do it correctly.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to show XML frame with slash command

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