Module:ItemsByStat

Revision as of 14:30, 27 September 2024 by SerpentofSet (talk | contribs)

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

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

local selectByStat = function(stat)
	local Name,Tier,Value = {},{},{}
	local outData = {Name,Tier,Value}
	local inKeys = {"Name","Tier",stat}; print(#inKeys)
	local i = 1
	
	for m,itemData in pairs(AllItemData) do
		for itemFieldName,n in pairs(itemData) do
			if itemFieldName == stat then 
				for x = 1,#inKeys do
					outData[x][i] = itemData[inKeys[x]]
					i = i+1; print(i)
					break
				end
			end
		end
	end
	return outData
end

p.tablefy = function(frame)
	local stat = frame.args[1]
	local tabledata = selectByStat(stat)
	Item = tabledata[1]
	Value = tabledata[3]
	output = ""
	for i=1,#Item do
		output = output.."Name: [["..Item[i].."]]	Increased Weapon Damage: "..Value[i].."\n\n"
	end
	return output
end

return p