ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   trying to build table, getting 'attempt to index a nil value' error (https://www.esoui.com/forums/showthread.php?t=8960)

ensiferumviking 02/11/20 08:00 PM

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


ensiferumviking 02/11/20 09:46 PM

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


Keldor 02/12/20 01:11 AM

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.

Baertram 02/12/20 07:19 AM

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 :D ).

ensiferumviking 02/12/20 03:18 PM

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.


All times are GMT -6. The time now is 10:59 AM.

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