Thread Tools Display Modes
05-07-07, 08:07 PM   #1
hellis
A Defias Bandit
Join Date: May 2007
Posts: 3
XML/LUA returns a nil value

I'm brand new to coding WoW addons so go easy on me

When I try to call a function (MyAddon_OnLoad() between the <OnLoad></OnLoad> tags in my XML code it always returns a nil value, why is this? I have a couple slash commands in the LUA in the function MyAddon_OnLoad(); but it always returns a nil value.

I'm coding for 1.12.1 because WoWUIDesigner is currently @ 1.12.1.

Any help is appreciated. Thank you.
  Reply With Quote
05-07-07, 10:29 PM   #2
Riraito
An Aku'mai Servant
 
Riraito's Avatar
Join Date: Dec 2006
Posts: 32
can we see your code? :P
__________________
  Reply With Quote
05-07-07, 11:21 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by hellis
I'm coding for 1.12.1 because WoWUIDesigner is currently @ 1.12.1.
If your client is at 2.x, then you need to code for 2.x. Any functions that used to be possible with 1.12, but aren't with 2.0, will not work whether WowUIDes is 1.12 or not.
__________________
"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
05-08-07, 03:39 AM   #4
hellis
A Defias Bandit
Join Date: May 2007
Posts: 3
LUA:
Code:
function AdvancedPMSForm_OnLoad()
    SLASH_AdvancedPMS1 = "/advancedpms";
    SLASH_AdvancedPMS2 = "/apms";

    SlashCmdList["AdvancedPMS"] = function(msg)
    AdvancedPMS_SlashCommandHandler(msg);
    end

        DEFAULT_CHAT_FRAME:AddMessage("AdvancedPMS Loaded");
end

function AdvancedPMS_SlashCommandHandler(msg)
     if (msg == "reload") then
         ReloadUI();                  
     elseif (msg == "test") then
         outSYS("another msg");
     end
     
end
XML:
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <!--Autogenerated by wowuides, Version=1.0.300.0, Culture=neutral, PublicKeyToken=null-->
  <Frame name="AdvancedPMSForm" hidden="true">
    <!--<FrameSkin skinid="dcb143e1-a4ab-4e7c-b934-1efa40101d21" frameid="2d508883-59c2-4f83-ae10-27aaad48391b" />-->
    <Size>
      <AbsDimension x="397" y="402" />
    </Size>
    <Anchors>
      <Anchor point="CENTER" relativeTo="UIParent">
        <Offset>
          <AbsDimension x="0" y="0" />
        </Offset>
      </Anchor>
    </Anchors>
    <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
      <BackgroundInsets>
        <AbsInset left="11" right="12" top="12" bottom="11" />
      </BackgroundInsets>
      <TileSize>
        <AbsValue val="32" />
      </TileSize>
      <EdgeSize>
        <AbsValue val="32" />
      </EdgeSize>
    </Backdrop>
    <Layers>
      <Layer>
        <Texture name="$parentTitleBorder" file="Interface\DialogFrame\UI-DialogBox-Header">
          <Size>
            <AbsDimension x="160" y="32" />
          </Size>
          <Anchors>
            <Anchor point="TOP">
              <Offset>
                <AbsDimension x="0" y="5" />
              </Offset>
            </Anchor>
          </Anchors>
          <TexCoords left="0.2" right="0.8" top="0" bottom="0.6" />
        </Texture>
        <FontString name="$parentTitleString" font="Fonts\FRIZQT__.TTF" text="AdvancedPMS">
          <Size>
            <AbsDimension x="140" y="0" />
          </Size>
          <Anchors>
            <Anchor point="TOP">
              <Offset>
                <AbsDimension x="0" y="-4" />
              </Offset>
            </Anchor>
          </Anchors>
          <FontHeight>
            <AbsValue val="12" />
          </FontHeight>
          <Color r="1" g="0.8196079" b="0" />
          <Shadow>
            <Color r="0" g="0" b="0" />
            <Offset>
              <AbsDimension x="1" y="-1" />
            </Offset>
          </Shadow>
        </FontString>
      </Layer>
    </Layers>
    <Frames>
      <Button name="BTNdone" text="Done">
        <!--<FrameSkin skinid="dcb143e1-a4ab-4e7c-b934-1efa40101d21" frameid="2d508884-59c2-4f83-ae10-27aaad48391b" />-->
        <Size>
          <AbsDimension x="71" y="24" />
        </Size>
        <Anchors>
          <Anchor point="TOPLEFT">
            <Offset>
              <AbsDimension x="308" y="-358" />
            </Offset>
          </Anchor>
        </Anchors>
        <NormalTexture file="Interface\Buttons\UI-Panel-Button-Up">
          <TexCoords left="0" right="0.625" top="0" bottom="0.6875" />
        </NormalTexture>
        <PushedTexture file="Interface\Buttons\UI-Panel-Button-Down">
          <TexCoords left="0" right="0.625" top="0" bottom="0.6875" />
        </PushedTexture>
        <DisabledTexture file="Interface\Buttons\UI-Panel-Button-Disabled">
          <TexCoords left="0" right="0.625" top="0" bottom="0.6875" />
        </DisabledTexture>
        <HighlightTexture file="Interface\Buttons\UI-Panel-Button-Highlight" alphaMode="ADD">
          <TexCoords left="0" right="0.625" top="0" bottom="0.6875" />
        </HighlightTexture>
        <ButtonText name="$parentText">
          <FontHeight>
            <AbsValue val="10" />
          </FontHeight>
        </ButtonText>
        <NormalFont inherits="GameFontNormal" font="Fonts\FRIZQT__.TTF">
          <FontHeight>
            <AbsValue val="12" />
          </FontHeight>
          <Color r="1" g="0.8196079" b="0" />
          <Shadow>
            <Color r="0" g="0" b="0" />
            <Offset>
              <AbsDimension x="1" y="-1" />
            </Offset>
          </Shadow>
        </NormalFont>
        <HighlightFont inherits="GameFontHighlight" font="Fonts\FRIZQT__.TTF">
          <FontHeight>
            <AbsValue val="12" />
          </FontHeight>
          <Color r="1" g="1" b="1" />
          <Shadow>
            <Color r="0" g="0" b="0" />
            <Offset>
              <AbsDimension x="1" y="-1" />
            </Offset>
          </Shadow>
        </HighlightFont>
        <DisabledFont inherits="GameFontDisable" font="Fonts\FRIZQT__.TTF">
          <FontHeight>
            <AbsValue val="12" />
          </FontHeight>
          <Color r="0.4980392" g="0.4980392" b="0.4980392" />
          <Shadow>
            <Color r="0" g="0" b="0" />
            <Offset>
              <AbsDimension x="1" y="-1" />
            </Offset>
          </Shadow>
        </DisabledFont>
      </Button>
    </Frames>
    <Scripts>
      <OnLoad>
    SLASH_AdvancedPMS1 = "/advancedpms";
    SLASH_AdvancedPMS2 = "/apms";

    SlashCmdList["AdvancedPMS"] = function(msg)
    AdvancedPMS_SlashCommandHandler(msg);
    end
        DEFAULT_CHAT_FRAME:AddMessage("AdvancedPMS Loaded");
      </OnLoad>
    </Scripts>
  </Frame>
</Ui>
This actually works but if I replace what's between the <OnLoad> tags in the XML with simply: AdvancedPMS_OnLoad(); it'll return a nil value.
  Reply With Quote
05-08-07, 06:13 AM   #5
Riraito
An Aku'mai Servant
 
Riraito's Avatar
Join Date: Dec 2006
Posts: 32
try adding <Script file="MyAddon.lua"/> (or what ever your lua file name is), right after the

<Ui xmlns="http://www.blizzard.com/wow/ui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
__________________
  Reply With Quote
05-08-07, 08:30 AM   #6
Rollak
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 36
You're right. Your onload should look like this.

Code:
<OnLoad>
     AdvancedPMSForm_OnLoad()
</OnLoad>
What order are the files being called for in the .toc? It should be

MyAddon.lua
MyAddon.xml

If the XML is loaded before the .lua, the function doesn't exist yet when the frame tries to perform the OnLoad function.
  Reply With Quote
05-08-07, 01:09 PM   #7
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Or he can leave his OnLoad handler the way he has it, then not worrying about the order in the .toc or adding a <Script> line... but if you do that you should remove AdvancedPMSForm_OnLoad() since it has no purpose
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
05-08-07, 03:21 PM   #8
hellis
A Defias Bandit
Join Date: May 2007
Posts: 3
Thank you very much, but I have come across something else, when I use the following code:
Code:
UIErrorsFrame:AddMessage(author.." whispers: "..text, 1.0, 1.0, 0, 1,120);
The last portion, the 120 (the hold time according to WoWWiki) is not working, its not holding for more than 10 or 20 seconds. Is there something I'm missing?
  Reply With Quote
05-08-07, 09:29 PM   #9
Rollak
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 36
Originally Posted by Shirik
Or he can leave his OnLoad handler the way he has it, then not worrying about the order in the .toc or adding a <Script> line... but if you do that you should remove AdvancedPMSForm_OnLoad() since it has no purpose
He could. However, I prefer to have all the scripts in the .lua file, and just use the .xml for the frames. It's easier for me that way, and I seems to be a bit cleaner.

Also, it makes it easier to use a Syntax highlighting editor, because LUA code is in the .lua and XML is in the .xml.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » XML/LUA returns a nil value


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