Array isempty when printed

Hello I have an array defined as such:

local BackpackDefs = {}

--// DEFAULTS
BackpackDefs.Defaults = {}
BackpackDefs.Defaults.MaxHolding = 40
BackpackDefs.Defaults.CurrentHeld = 0
BackpackDefs.Defaults.Lettuce = 0
BackpackDefs.Defaults.Shells = 0
BackpackDefs.Defaults.Cheese = 0
BackpackDefs.Defaults.Meat = 0

--// KEY TABLES
BackpackDefs.AllKeys = {MaxHolding,CurrentHeld,Lettuce,Shells,Cheese,Meat}
BackpackDefs.IngredientKeys = {Lettuce,Shells,Cheese,Meat}

return BackpackDefs

Refrenscing the Default values above seems to work fine, but when i try and index the arrays BackpackDefs.AllKeys and BackpackDefs.IngredientKeys they return nothing, they dont seem to be nil but when trying to see their entries, it is blank.

For example when i do:

print(#BackpackDefs.AllKeys)
print(#BackpackDefs.IngredientKeys)

I get 0 and 0

Anyone know what I am doing wrong? THANKS!

1 Like

All of those values (MaxHolding, CurrentHeld, Lettuce, etc.) are nil inside the table.

Running #table does not include nil values, I believe.

1 Like

MaxHolding, CurrentHeld, ect are probably just undeclared and thus the table looks like

{nil, nil, nil}

1 Like

im just trying to create an array, where those names are the values stored inside AllKeys. how do i do that?

I think you meant the values to be strings, so you would do

BackpackDefs.AllKeys = {"MaxHolding", "CurrentHeld", "Lettuce", "Shells", "Cheese", "Meat"}

And you’d do the same for IngredientKeys
(tbh I recommend AllValues as your key)

1 Like

thanks! Yes they should be strings :slight_smile:

BTW they are actually keys used in another operation to create valueobjects and savedata. So they will have values when they are used.

1 Like

I’m fairly certain that you cannot use the # to get the length of a dictionary, only tables with numbered indexes.