Thread Tools Display Modes
05/01/14, 08:02 AM   #1
Feroc
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 5
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:
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?
  Reply With Quote
05/01/14, 09:32 AM   #2
mra4nii
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 42
You try to print something to chat window when the window doesn't exist yet.
You need another event here:
try this:
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);
  Reply With Quote
05/01/14, 09:37 AM   #3
Feroc
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 5
Thanks, that helps a lot.

Didn't guess that the addons were loaded before the actual GUI.
  Reply With Quote
05/01/14, 09:41 AM   #4
mra4nii
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 42
You may want to take a look at this 2 addons as an example:
Sample Application (For new developers)
ins:AddonTest
  Reply With Quote
05/01/14, 09:57 AM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Feroc View Post
...
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)
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Already failing at Event_Add_on_Loaded


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