Monday, April 16, 2012

Basic script error (a nil value)

Can someone take a quick a look at the code below and tell me what is causing this error? I made this quick add on while learning how to use WoWAddon. It may be that the code it creates is just out of date for current WoW UI, but I can't find what it is that is wrong.

If I remove lines 34-35 of the xml, I don't get the error, but the button doesn't work then of course. Also, the frame is not click-draggable ever, like it is supposed to be. Otherwise, the addon does do what it is supposed to. It replaces some text with target's name.

Thanks much.

Error:


Code:
Date: 2009-12-03 16:42:21
ID: 1
Error occured in: Global
Count: 1
Message: [string "Okeydokey:OnLoad"] line 1:
attempt to call global 'Okeydokey_OnLoad' (a nil value)
Debug:
[C]: Okeydokey_OnLoad()
[string "*:OnLoad"]:1:
[string "*:OnLoad"]:1

Frame.xml:


Code:
<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.blizzard.com/wow/ui/">
<Script file="Frame.lua" />
<Frame name="Frame1" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
<Size>
<AbsDimension x="328" y="200" />
</Size>
<Anchors>
<Anchor point="CENTER">
<Offset x="64" y="0" />
</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>
<Frames>
<Button name="Okeydokey" inherits="UIPanelButtonTemplate" text="Ok!">
<Size>
<AbsDimension x="93" y="34" />
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset x="26" y="-59" />
</Anchor>
</Anchors>
<Scripts>
<OnLoad>Okeydokey_OnLoad();</OnLoad>
<OnClick>Okeydokey_OnClick();</OnClick>
</Scripts>
<ButtonText name="$parentText" text="" />
</Button>
</Frames>
<Layers>
<Layer level="OVERLAY">
<FontString name="FontString1" inherits="GameFontNormal" text="Hello World!">
<Size>
<AbsDimension x="150" y="20" />
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset x="26" y="-32" />
</Anchor>
</Anchors>
</FontString>
</Layer>
</Layers>
<Scripts>
<OnLoad>Frame1_OnLoad();</OnLoad>
<OnDragStart>self:StartMoving();</OnDragStart>
<OnDragStop>self:StopMovingOrSizing();</OnDragStop>
<OnEvent>Frame1_OnEvent();</OnEvent>
</Scripts>
</Frame>
</Ui>

Frame.lua:


Code:
function Frame1_OnLoad()
this:RegisterEvent("PLAYER_TARGET_CHANGED");
end


function Frame1_OnEvent()
if (event == "PLAYER_TARGET_CHANGED") then
FontString1:SetText("Hello " .. UnitName("target") .. "!");
end
end

function Okeydokey_OnClick()
Frame1:Hide();
end

FirstAddOn.toc:


Code:
## Title: FirstAddOn
## Version: 1.0
## Author: Bonewalker
## Interface: 30200

Frame.xml
|||The error tells you all you need to know.

Your Frame.lua does not contain a function Okeydokey_OnLoad().

There's not much to explain, you need to declare functions before you can call them.|||Arrgghh...of course you are right. I wonder why that thing would produce code that doesn't match up correctly?

Anyway, any thoughts as to why the frame isn't draggable?

Thanks, Drizzd.

No comments:

Post a Comment