Need help with receiving stuff from a table (solved)

Item list (2 categories, imagine numerous items within each category).

local biglist = {
	
	["Items"] = {
		{
			Name = "Test Item";
			Type = "Sword";
			UUID = nil;
		};
	},
	
	["Consumables"] = {
		{
			Name = "Vigilant Ash";
			Type = "Consumable";
			UUID = nil;
		};
	}
	
	
}

The actual script (one gives outs a warning even though it succeeds):

local item = invmod:retrieveItemFromData("Test Item")
local item2 = invmod:retrieveItemFromData("Vigilant Ash")

The module script that is called, I may be doing something wrong here, that’s why I need help.

local function checkItemExistence(itemData)
	for _,v in pairs(itemsData) do
		for i,x in pairs(v) do
			if x.Name == itemData.Name then
				return true
			else
				return false
			end
		end
	end
end

function inventoryHandler:retrieveItemFromData(item)
	for _,v in pairs(itemsData) do
		for i,x in pairs(v) do
			if x.Name == item then
				return x
			elseif checkItemExistence(itemsData) == false then
				warn(x.Name .." does not exist in the game data, please check for typos.")
			end
		end
	end
end

This is the output:

  23:28:20.582 - Test Item does not exist in the game data, please check for typos.

  Test Item 43FF5060-C92C-4AAE-B4C8-0E9073E13F38

As you can see the table contradicts itself since it does receive Test Item but it still says it does not exist, and also its not taking the “Vigilant Ash” which it’s supposed to print out as well.

To be honest its probably worth just using a normal array. When you check all the Stuff in the dictionary in the script you are using. It will see [“Consumables”] and [“items”].

You have created another array inside the consumables and items with extra ‘{ }’
This means that when you try to get things from the dictionary it wont find them, as they only value it has is a table.

1 Like