Thread Tools Display Modes
06/16/17, 07:26 AM   #1
Devisaur
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 6
Variable Initalization Issue

************
Solved - XML Control had the same name as the addon
***********


I'm fairly new to Lua so perhaps I'm missing something obvious. My IF statement that is checking the addon name keeps failing -- after doing some digging I've found that my TimetoLevel.name is never being set.

Is there a reason that these variables would fail set?

Code:
TimetoLevel = {}
TimetoLevel.name = "TimetoLevel"

function TimetoLevel.Initalize(eventCode, addOnName)
	--TimetoLevelCounter:SetText(string.format(TimetoLevel.name)
	if ( addOnName ~= TimetoLevel.name ) then
		return
	end
	
	TimetoLevel.XP = GetUnitXP('player')
	TimetoLevel.levelXP = GetNumExperiencePointsInLevel(GetUnitLevel('player')) 
	TimetoLevel.remainingXP = TimetoLevel.levelXP - TimetoLevel.XP
	TimetoLevelCounter:SetText(string.format(addOnName))

	EVENT_MANAGER:UnregisterForEvent(TimetoLevel.name, EVENT_ADD_ON_LOADED)
end


EVENT_MANAGER:RegisterForEvent(TimetoLevel.name, EVENT_ADD_ON_LOADED, TimetoLevel.Initalize)
The above code works fine if I do:
Code:
if ( addOnName ~= "TimetoLevel" ) then
		return
	end
Here is my text file as well
Code:
## Title: TimetoLevel
## Description: Devisaurs Time to Level Version 1.0
## APIVersion: 100019

TimetoLevel.lua
TimetoLevel.xml

Last edited by Devisaur : 06/16/17 at 06:40 PM. Reason: Solution found
  Reply With Quote
06/16/17, 07:47 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
It's the folder name of your addon which matters.
  Reply With Quote
06/16/17, 07:53 AM   #3
Devisaur
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 6
Originally Posted by Ayantir View Post
It's the folder name of your addon which matters.
My folder name is TimetoLevel

Documents\Elder Scrolls Online\live\AddOns\TimetoLevel

Last edited by Devisaur : 06/16/17 at 07:55 AM. Reason: Included specific Addon Name
  Reply With Quote
06/16/17, 09:09 AM   #4
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
Just a tip, but I figured I may as well mention that your description is data better placed elsewhere and you should describe what the addon does in the description.

Code:
;Having a comment here helps with formatting issues.

## Title: TimetoLevel
## APIVersion: 100019
## Author: Devisaur
## Description: Devisaurs Time to Level Version 1.0
## Version: 1.0

TimetoLevel.lua
TimetoLevel.xml
  Reply With Quote
06/16/17, 10:22 AM   #5
Devisaur
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 6
Originally Posted by Rhyono View Post
Just a tip, but I figured I may as well mention that your description is data better placed elsewhere and you should describe what the addon does in the description.

Code:
;Having a comment here helps with formatting issues.

## Title: TimetoLevel
## APIVersion: 100019
## Author: Devisaur
## Description: Devisaurs Time to Level Version 1.0
## Version: 1.0

TimetoLevel.lua
TimetoLevel.xml
This isn't finalized by any means. Still no resolution of the addon-name issue. I'm going to try recreating the folder maybe that will fix it.

#Edit -- Recreating the folder didn't fix the issue.

Last edited by Devisaur : 06/16/17 at 10:42 AM. Reason: Spelling
  Reply With Quote
06/16/17, 11:12 AM   #6
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
The name of the text file needs to match the folder name. However if your code can work when you hard code the name, it looks like it's already loading. In that case, here's what I would do. install pChat, and set it as an optional depends on in the text file. Then add d() all over. Check that timestolevel is actually created, check that the name is correct when you declare it and before you pass it to the event manager. Check that it's correct when the initialization function is run and right before/after you do the check of the name, and output all the add-on names passed to your initialization function. It sounds tediuoz but if you have no clue, it can help.

Last edited by Dolgubon : 06/16/17 at 11:16 AM.
  Reply With Quote
06/16/17, 03:41 PM   #7
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
My guess is that your problem is in your xml file. You most likely named a control "TimetoLevel" and it overwrites your table.
  Reply With Quote
06/16/17, 06:39 PM   #8
Devisaur
AddOn Author - Click to view addons
Join Date: Jun 2017
Posts: 6
Originally Posted by sirinsidiator View Post
My guess is that your problem is in your xml file. You most likely named a control "TimetoLevel" and it overwrites your table.
Yep -- you were right I changed it to TimetoLevelUI and it works perfectly. Thanks everyone for your help

Last edited by Devisaur : 06/16/17 at 06:48 PM. Reason: spelling
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Variable Initalization Issue

Thread Tools
Display Modes

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