Thread Tools Display Modes
08/28/21, 04:56 PM   #1
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Unnamed outfits have empty string as name

Hey there!

I'm working on my wardrobe manager mod, and any outfit that has been recently unlocked has an empty string for its name even though its label is "Outfit N." This breaks my code and prevents my LAM dropdowns from populating correctly.

I tried implementing a fix that renamed any unnamed outfits to the label (Outfit N) which got the job done, but the first time that code runs it throws the error listed below. Also below is the relevant code and a link to the project on Github.

Full code

Lua Code:
  1. function LWM:Initialize()
  2.     LWM.vars = ZO_SavedVars:NewCharacterIdSettings("LWMVars", LWM.variableVersion, nil, LWM.default, GetWorldName())
  3.  
  4.     self.inCombat = IsUnitInCombat("player")
  5.     self.inStealth = GetUnitStealthState("player")
  6.  
  7.     for i=1,GetNumUnlockedOutfits() do
  8.         name = GetOutfitName(0, i)
  9.         -- TODO: This throws an error the first time it runs, fix it
  10.         if name == '' then
  11.             RenameOutfit(0, i, "Outfit " .. tostring(i))
  12.         end
  13.         self.allOutfits[i + OUTFIT_OFFSET] = name
  14.     end
  15.     ...
  16. end

Error:
Code:
user:/AddOns/LeonardosWardrobeManager/LeonardosWardrobeManager.lua:112: attempt to index a nil value
stack traceback:
user:/AddOns/LeonardosWardrobeManager/LeonardosWardrobeManager.lua:112: in function 'LeonardosWardrobeManager.OnOutfitRenamed'
|caaaaaa<Locals> event = 131661, response = 0, index = 0 </Locals>|r
  Reply With Quote
08/29/21, 04:39 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,913
Line 112 is an end?
Please update the error message to your current github code lines so one sees where exactly it errors!

btw PLEASE do not use the constant values like 0 for the actor category BUT use the given constants!
They might change and your code should always use constants like BAG_BAGPACK instead of 1 and GAMEPLAY_ACTOR_CATEGORY_* instead of 0 or 1!
That's why constants were created :-)

Edit:
If the line here is the errror: if name == '' then

You check for name == string but name will be nil in that case you have described.
So you need to add a nil check like this:

if not name or name == '' then

or more simple
name = GetOutfitName(GAMEPLAY_ACTOR_CATGORY_PLAYER, i) or ''
the or '' will react and add an empty string if GetOutfitName returns nil

or just another notation
name = GetOutfitName(GAMEPLAY_ACTOR_CATGORY_PLAYER, i)
if not name then name = '' end

or

name = name or '' --the same as above

Last edited by Baertram : 08/29/21 at 04:43 AM.
  Reply With Quote
08/29/21, 01:06 PM   #3
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Thanks so much for your help, I got it all working!!

Originally Posted by Baertram View Post
Line 112 is an end?
Please update the error message to your current github code lines so one sees where exactly it errors!

btw PLEASE do not use the constant values like 0 for the actor category BUT use the given constants!
They might change and your code should always use constants like BAG_BAGPACK instead of 1 and GAMEPLAY_ACTOR_CATEGORY_* instead of 0 or 1!
That's why constants were created :-)

Edit:
If the line here is the errror: if name == '' then

You check for name == string but name will be nil in that case you have described.
So you need to add a nil check like this:

if not name or name == '' then

or more simple
name = GetOutfitName(GAMEPLAY_ACTOR_CATGORY_PLAYER, i) or ''
the or '' will react and add an empty string if GetOutfitName returns nil

or just another notation
name = GetOutfitName(GAMEPLAY_ACTOR_CATGORY_PLAYER, i)
if not name then name = '' end

or

name = name or '' --the same as above
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Unnamed outfits have empty string as name

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