Thread Tools Display Modes
02/11/20, 08:00 PM   #1
ensiferumviking
Join Date: Jun 2014
Posts: 5
trying to build table, getting 'attempt to index a nil value' error

I'm still getting used to the lua table/key conventions. Here's the code that's causing problems:

Code:
local toonName=GetUnitName("reticleover")
PlayerInfoLogger.fullList[toonName]={}
That second line causes the error. 'toonName' is successfully resolving to a string. Can I not use a string variable as an index? fullList should be initialized to an empty table:

Code:
PlayerInfoLogger.Default={
  fullList={}
}
function PlayerInfoLogger:Initialize()
  --Define Saved Variables
  self.savedVariables=ZO_SavedVars:NewAccountWide("PlayerInfoLoggerSavedVariables", 1, nil, {PlayerInfoLogger.Default})

  --If there's a saved value, use that.
  PlayerInfoLogger.fullList=self.savedVariables.fullList
end
Is there a way to check that 'fullList' is indeed getting intialized? I've been able to verify the the Initialize function does get called.

Here's the txt manifest file:
Code:
## Title: Genesis PlayerInfoLogger
## Author: |c999999Genesis1701d
## Version: 3.15
## Description: Logs basic information about the characters around you.
## APIVersion: 100028
## SavedVariables: PlayerInfoLoggerSavedVariables
  Reply With Quote
02/11/20, 09:46 PM   #2
ensiferumviking
Join Date: Jun 2014
Posts: 5
Update, I've sort of fixed it. I changed the initialization routine to explicitly default the fullList variable instead of relying on the built in Default table to do it.... but I'd still appreciate any insight into why that didn't work.

Code:
function PlayerInfoLogger:Initialize()
  --Define Saved Variables
  self.savedVariables=ZO_SavedVars:NewAccountWide("PlayerInfoLoggerSavedVariables", 2, nil, {PlayerInfoLogger.Default})

  --If there's a saved value, use that.
  PlayerInfoLogger.fullList=self.savedVariables.fullList
  if(PlayerInfoLogger.fullList==nil) then
    PlayerInfoLogger.fullList={}
  end
end
  Reply With Quote
02/12/20, 01:11 AM   #3
Keldor
 
Keldor's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 101
I think your problem is the default var in the saved variables init method. You have this

Lua Code:
  1. self.savedVariables=ZO_SavedVars:NewAccountWide("PlayerInfoLoggerSavedVariables", 2, nil, {PlayerInfoLogger.Default})

You have already a default table. Can you try to remove the braces around the PlayerInfoLogger.Default var?

Lua Code:
  1. self.savedVariables=ZO_SavedVars:NewAccountWide("PlayerInfoLoggerSavedVariables", 2, nil, PlayerInfoLogger.Default)

You should also delete your saved vars before this change while the game is not running to avoid the loading of old invalid data.
  Reply With Quote
02/12/20, 07:19 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,903
Code:
{PlayerInfoLogger.Default}
Will be the same as defining a anonymous table without name and assigning the first entry with key = value -> [1] = the other table PlayerInfoLogger.Default
e.g.
Lua Code:
  1. local table1 = {
  2.    [1] = PlayerInfoLogger.Default
  3. }

But for the SavedVariables you need a table with the entries of your SavedVariables,
and not a table containing a table (unless your SV needs the subtable ).
  Reply With Quote
02/12/20, 03:18 PM   #5
ensiferumviking
Join Date: Jun 2014
Posts: 5
Thank you both, that makes total sense.

I'm itching to test it out now but *sigh* zeni is having their own breed of technical difficulties at the moment and i can't login.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » trying to build table, getting 'attempt to index a nil value' error

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