Module:ItemsByStat: Difference between revisions
Jump to navigation
Jump to search
SerpentofSet (talk | contribs) mNo edit summary |
SerpentofSet (talk | contribs) mNo edit summary |
||
Line 3: | Line 3: | ||
local selectByStat = function(stat) | local selectByStat = function(stat) | ||
local Name,Tier, | local inKeys = {"Name","Tier","Cost","Slot",stat} | ||
local outData = { | local outData = {} | ||
for x=1,#inKeys do | |||
outData[x] = {} | |||
end | |||
local i = 1 | local i = 1 | ||
Line 11: | Line 13: | ||
for itemFieldName,n in pairs(itemData) do | for itemFieldName,n in pairs(itemData) do | ||
if itemFieldName == stat then | if itemFieldName == stat then | ||
for x = 1, | for x = 1,#inKeys do | ||
outData[x][i] = itemData[inKeys[x]] | outData[x][i] = itemData[inKeys[x]] | ||
end | end | ||
Line 27: | Line 29: | ||
local outString = "" | local outString = "" | ||
for i=1,#tableData[1] do | for i=1,#tableData[1] do | ||
outString = | outString = tableData[1][i]..tableData[2][i]..tableData[3][i]..tableData[4][i]..tableData[5][i].."\n\n" | ||
end | end | ||
return outString | return outString |
Revision as of 14:46, 27 September 2024
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 inKeys = {"Name","Tier","Cost","Slot",stat}
local outData = {}
for x=1,#inKeys do
outData[x] = {}
end
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]]
end
i = i+1
break
end
end
end
return outData
end
p.tablefy = function(frame)
local stat = frame.args[1]
local tableData = selectByStat(stat)
local outString = ""
for i=1,#tableData[1] do
outString = tableData[1][i]..tableData[2][i]..tableData[3][i]..tableData[4][i]..tableData[5][i].."\n\n"
end
return outString
end
return p