• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Trouble with Tables (1 Viewer)

Dounford

Newcomer
Joined
May 18, 2021
Messages
1
Reaction score
0
Hello, I am new with Lua and I was trying to make a table using Databases on Fandom (the table itself is MediaWiki, but the DB to the table part is what I am having problems with), I managed to do it, but there is something lacking in my code. However, I was unable to find a similar project to discover what I should add, here is the problem, all "Materials" of the same item should be on a single row, instead of creating a new row for each material.
table.PNG
The code is:
Lua:
u = require("Module:Util")
db = require("Module:Crafting_DB")

local p = {}

function p.furnace()
    recipes = {}
    for _, e in ipairs(db) do
        if e[3] == 1 then
            for _, f in ipairs(e[6]) do
                table.insert(recipes, {e[1], e[2], e[4], e[5], f[1], f[2], e[7]})
            end
        end
    end
    result = [[
{| class="loot-table"
! colspan="2" style="width: 30%" |Item
!Level
!XP
! style="width: 20%" |Materials
! style="width: 25%" |Description
]]
    for _, e in ipairs(recipes) do
        result = result .. [[
|-
|]] .. '[[' .. e[1] .. ']]' .. [[

|]] .. '[[File: ' .. e[2] .. '.png|35px|link=' .. e[1] .. ']]' .. [[
 
|]] .. e[3] .. [[
 
|]] .. e[4] .. [[

|]] .. '[[File: ' .. (e[5]:gsub(' ', ''):gsub('%(', ''):gsub('%)', '')) .. '.png|35px|link=' .. e[5] .. ']]' .. ' ' .. e[6] .. [[

|]] .. e[7] .. [[
 
]]
    end
    return result .. [[
|}
]]
end
The Database is something like this:
Lua:
-- Format: {Item Name,Image File Name,Group,Crafting Level,Crafting XP,{Mateial1,Material2, ...},Item Description,Notes(optional)},
-- Material Format: {Material Name,Amount Needed},
{'Bronze Furnace','BronzeFurnace',1,12,200,{{'Stone',200},{'Bronze Bars',100},{'Stone Furnace',1}},'Increases your Furnace capacity to 30'},
I don't think the DB or the table itself are the problem, I guess I should add something near the table.insert, can someone help me?
 
Top