ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Variable Initalization Issue (https://www.esoui.com/forums/showthread.php?t=7145)

Devisaur 06/16/17 07:26 AM

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


Ayantir 06/16/17 07:47 AM

It's the folder name of your addon which matters.

Devisaur 06/16/17 07:53 AM

Quote:

Originally Posted by Ayantir (Post 31464)
It's the folder name of your addon which matters.

My folder name is TimetoLevel

Documents\Elder Scrolls Online\live\AddOns\TimetoLevel

Rhyono 06/16/17 09:09 AM

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


Devisaur 06/16/17 10:22 AM

Quote:

Originally Posted by Rhyono (Post 31466)
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.

Dolgubon 06/16/17 11:12 AM

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.

sirinsidiator 06/16/17 03:41 PM

My guess is that your problem is in your xml file. You most likely named a control "TimetoLevel" and it overwrites your table.

Devisaur 06/16/17 06:39 PM

Quote:

Originally Posted by sirinsidiator (Post 31473)
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 :)


All times are GMT -6. The time now is 04:15 PM.

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