lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, Jan 19, 2011 at 4:59 PM, Svein Arne Nilsen <> wrote:
> Hi
> Im new to lua and wondering if i can get some help.
> This is a sampel addon iv pickt up.

Unfortunately this is not really the right location for the help
you're trying to get. You should post on one of the many World of
Warcraft forums/sites:

This mailing list is for the Lua programming language and discussions
for the language. Your question is about the way addons work for World
of Warcraft.

> local HelloWorld = {} -- the AddOn namespace, all your functions should be
> placed inside here instead of as globals.
> _G.HelloWorld = HelloWorld -- expose it to the global scope
> local frame = _G.HelloWorld_Frame -- made in the XML
> --- Print out "Hello, World!" to the chat frame
> -- @usage HelloWorld.Print()
> function HelloWorld.Print()
>   DEFAULT_CHAT_FRAME:AddMessage("Hello, World!")
> end
> frame:RegisterEvent("VARIABLES_LOADED")                     <--  it stopps
> here saying its a nil value
> function HelloWorld:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7,
> arg8, arg9)
>   -- this is a fun trick that will call a method named the event, passing
> in all the relevant args.
>   self[event](self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
> end
> function HelloWorld:VARIABLES_LOADED()
>   self.Print()
> end

If frame is a 'nil' value, that means the frame from your XML was not
created, or was not created at the time this Lua script was run.

You are making things that are very simple very very complicated.
Without understanding your intent or what you're working from, I'm not
quite sure how to help.

local addon, addonName = ...
addon.frame = CreateFrame("Frame", "HelloFrame")
addon.frame:SetScript("OnEvent", function(self, event, ...)
  print("Hello World from addon " .. addonName)

- Jim