Issue: My index, key (i,v) identifiers (aka the categoryContents, filteredContents) returns nil when indexed as follows: print(CategoryContents.filteredContents)
When independent, they are printed just fine (ex: print(categoryContents, filteredContents)
Goal: My goal is to have my index and key be a replacement to search through a NESTED DICTIONARY
--This Module is responsible for any functions of which change the player's data.--
local httpService = game:GetService("HttpService")
local itemCatalog = require(game.ServerStorage.Modules.itemCatalog)
local dataModule = {}
function dataModule.AddItem(player, item)
local playerInventory = player:GetAttribute("PlayerInventory")
for CategoryName,CategoryContents in pairs(itemCatalog.ItemDatabank) do --Enters the table.
for filteredCategory,filteredContents in pairs(CategoryContents) do --Goes deeper into the table.
for itemName,itemAttributes in pairs(filteredContents) do
if itemName == item then
print(playerInventory.CategoryName.CategoryContents) --returns nil (ERROR)
break
else
warn("Item could not be found.")
end
end
end
end
end
return dataModule```
We don’t really have a copy of your data. So you best help yourself on this one.
But what I would teach is how you use a debugger, watches, and breakpoints.
First, because lua, gives such nice errors, you got to figure out which is actually nil. playerInventory.CategoryName.CategoryContents
It could be playerInventory, or, it could be player
It could be CategoryName, CategoryContents
How I would think of it as one big statement. player:GetAttribute("PlayerInventory").CategoryName.CategoryContents
Towards the left, if that is a nil, the rest proceeding it will also be nil. For example: If CategoryName is null, CategoryContents will be as well.
The first step is you put a breakpoint in that print. Right click it and edit that breakpoint.
For the condition, put in playerInventory.CategoryName.CategoryContents == nil
It will break when that is nil.
When that breakpoint hits, a wonderful window called Watch will appear.
This window shows you local variables and their values.
See where this is going? Go through the watch and see which one is nil.
The rest of the detective work you can do.
Follow the path that set that value and see what that was nil.