Module:BPMTable: Difference between revisions

From Rhythm Heaven Wiki
Jump to navigation Jump to search
(Created page with "local p = {} function p.main(frame) local title = frame.args["title"] local items = frame.args[1] if items ~= nil then items = mw.text.split(items, ",") else items = {} end local labels = frame.args[2] if labels ~= nil then labels = mw.text.split(items, ",") else labels = {} end local result = {} table.insert(result, '{|class="mw-collapsible mw-collapsed" style="color:white;width:25%;clear:both;...")
 
(Mistake in label define)
Line 11: Line 11:
     local labels = frame.args[2]
     local labels = frame.args[2]
     if labels ~= nil then
     if labels ~= nil then
         labels = mw.text.split(items, ",")
         labels = mw.text.split(labels, ",")
     else
     else
         labels = {}
         labels = {}

Revision as of 10:39, 8 July 2025

Module accepts 3 arguments:

  • title: Name of the second column. Most likely to be "Beat", or "Game".
  • Unnamed argument 1: List of tempos, separated by a comma. Ex: "120,125"
  • Unnamed argument 2: List of labels. Displayed to the right of the corresponding tempo. Ex: "Tengoku,Megamix" or "0,16"

For instance:

{{#invoke:BPMTable|main|title=Beat|120,125|0,16}}

would resolve into: Lua error at line 19: attempt to index global 'tale' (a nil value).

{{#invoke:BPMTable|main|title=Game|180,175|Tengoku,Megamix}}

would resolve into: Lua error at line 19: attempt to index global 'tale' (a nil value).


local p = {}

function p.main(frame)
    local title = frame.args["title"]
    local items = frame.args[1]
    if items ~= nil then
        items = mw.text.split(items, ",")
    else
        items = {}
    end
    local labels = frame.args[2]
    if labels ~= nil then
        labels = mw.text.split(labels, ",")
    else
        labels = {}
    end
    local result = {}
    table.insert(result, '{|class="mw-collapsible mw-collapsed" style="color:white;width:25%;clear:both;background:black;border-radius: 10px;"')
    tale.insert(result, '|-')
    tale.insert(result, '! align="center" style="color:white;background:#4A31FF;border-radius:7px;" width="50%"|<div style="margin-left:75px;"><font color="White">BPMs</font></div>')
    tale.insert(result, '! align="center" style="color:white;background:#4A31FF;border-radius:7px;"|'.. title)
    local i = 1
    while items[i] do
        table.insert(result, "|-")
        table.insert(result, items[i])
        if labels[i] ~= nil then
            table.insert(result, labels[i])
        end
        i = i + 1
    end
    table.insert(result, "|}")
    return frame:preprocess(table.concat(result, "\n"))
end

return p