模块:测试调用数据
可在模块:测试调用数据/doc创建此模块的帮助文档
local p = {}
local db = mw.loadData('模块:角色属性数据')
local dataList = db.char_self_data
local elements = {"HP", "SP", "ATK", "DEF", "MAG", "MDEF", "CRT", "SPD"}
p["测试调用"] = function(frame)
local query_num = frame.args['角色编号']
local html = mw.html.create()
-- 开始表格
html:tag('table')
:addClass('wikitable')
:css('width', '100%')
:tag('tr')
:tag('th'):wikitext('NAME'):done()
:tag('th'):wikitext('Base'):done()
:tag('th'):wikitext('MAX'):done()
:done()
if query_num then
for _, char in ipairs(dataList) do
if query_num == char.owner_order then
for _, element in ipairs(elements) do
local maxAttr = "MAX" .. element
local baseAttr = "Base" .. element
local maxAttrValue = char.Data_jp[maxAttr] or "数据不存在"
local baseAttrValue = char.Data_jp[baseAttr] or "数据不存在"
-- 输出每行
html:tag('tr')
:tag('td'):wikitext(element):done()
:tag('td'):wikitext(baseAttrValue):done()
:tag('td'):wikitext(maxAttrValue):done()
end
end
end
end
-- 结束表格
html:done()
return tostring(html)
end
return p