Module:ItemTables: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sylphoid (talk | contribs)
Undo revision 6259 by Sylphoid (talk) back to tables, with concat
Sylphoid (talk | contribs)
table is string
Line 20: Line 20:
local item = get_json_item(item_name)
local item = get_json_item(item_name)
if(item == nil) then return "Item Not Found" end
if(item == nil) then return "Item Not Found" end
if(type(item) == table) then
if(type(item) == "table") then
for i,v in pairs(item) do
for i,v in pairs(item) do
local shopTableValues = table.insert(shopTableValues, v)
local shopTableValues = table.insert(shopTableValues, v)

Revision as of 07:10, 20 September 2024

Documentation for this module may be created at Module:ItemTables/doc

local p = {};
local data = mw.loadJsonData("Data:ItemData.json")

-- returns the table of a specific item
function get_json_item(name)
	for i,v in pairs(data) do
		if (v["Name"] == name) then
			return v
		end
	end
	return nil
end

--{{#invoke:Sandbox/Sylphoid|get_prop|ITEM_NAME|PROPERTY}}--
--check Data:ItemData.json for properties
p.get_prop = function(frame)
	local shopTableValues = {}
	local item_name = frame.args[1]
	local property = frame.args[2]
	local item = get_json_item(item_name)
	if(item == nil) then return "Item Not Found" end
	if(type(item) == "table") then
		for i,v in pairs(item) do
			local shopTableValues = table.insert(shopTableValues, v)
			--local tableValues = get_json_item(item)
		end
		return table.concat(shopTableValues, ", ")
	end
	return item[property]
	--return tableValues[property]
end

return p