ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Already failing at Event_Add_on_Loaded (https://www.esoui.com/forums/showthread.php?t=1300)

Feroc 05/01/14 08:02 AM

Already failing at Event_Add_on_Loaded
 
Hi there,

I am playing around a bit with LUA, but for me it looks like I set up something wrong.

I've tried it with the easiest examples of all:

TestOne.txt:

Code:

## Title: TestOne
## APIVersion: 100003

TestOne.lua

Test One lua:

Code:

function TestOne.Initialize(eventCode, addOnName)
        if (addOnName ~= "TestOne") then
                return
        end
        d("TestOne Loaded...")
end

EVENT_MANAGER:RegisterForEvent("TestOne", EVENT_ADD_ON_LOADED, TestOne.Initialize);

That already throws an error:
Quote:

user:/AddOns/TestOne/TestOne.lua:1: attempt to index a nil value
stack traceback:
user:/AddOns/TestOne/TestOne.lua:1: in function '(main chunk)'
If I change TestOne.Initialize to TestOneInitialize I don't get the error anymore... but I don't get a "TestOne Loaded" in the chat either. It just does nothing.

What am I doing wrong?

mra4nii 05/01/14 09:32 AM

You try to print something to chat window when the window doesn't exist yet.
You need another event here:
try this:
Quote:

local function LateInitialize(eventCode, addOnName)
d("TestOne addon loaded...")
-- chat window loaded, our text is printed, no need for this anymore too
EVENT_MANAGER:UnregisterForEvent("TestOne", EVENT_PLAYER_ACTIVATED)
end

local function Initialize(eventCode, addOnName)
if (addOnName ~= "TestOne") then
return
end
-- register for event when character actually enter to world
EVENT_MANAGER:RegisterForEvent("TestOne", EVENT_PLAYER_ACTIVATED, LateInitialize);
-- our addon is loaded, no need for this anymore
EVENT_MANAGER:UnregisterForEvent("TestOne", EVENT_ADD_ON_LOADED)
end


EVENT_MANAGER:RegisterForEvent("TestOne", EVENT_ADD_ON_LOADED, Initialize);

Feroc 05/01/14 09:37 AM

Thanks, that helps a lot.

Didn't guess that the addons were loaded before the actual GUI.

mra4nii 05/01/14 09:41 AM

You may want to take a look at this 2 addons as an example:
Sample Application (For new developers)
ins:AddonTest

Garkin 05/01/14 09:57 AM

Quote:

Originally Posted by Feroc (Post 6583)
...
Code:

function TestOne.Initialize(eventCode, addOnName)
        if (addOnName ~= "TestOne") then
                return
        end
        d("TestOne Loaded...")
end

EVENT_MANAGER:RegisterForEvent("TestOne", EVENT_ADD_ON_LOADED, TestOne.Initialize);

That already throws an error:


If I change TestOne.Initialize to TestOneInitialize I don't get the error anymore... but I don't get a "TestOne Loaded" in the chat either. It just does nothing.

What am I doing wrong?

You are trying to add something to table TestOne that does not exists. If you create that table first, it will work.
Lua Code:
  1. TestOne = {}
  2.  
  3. function TestOne.Initialize(eventCode, addOnName)
  4.     if (addOnName ~= "TestOne") then
  5.         return
  6.     end
  7.     d("TestOne Loaded...")
  8. end
  9.  
  10. EVENT_MANAGER:RegisterForEvent("TestOne", EVENT_ADD_ON_LOADED, TestOne.Initialize)


All times are GMT -6. The time now is 01:58 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI