Happy Early Access Launch! Please bear with us: We're doing our best to get the site updated. If we currently don't have what you're looking for, try checking our sister site, beastieball.info.

If you're looking to contribute to the site, we're happy to have you! Check out Beastiepedia:To Do List to see what needs done.

Find us in the Wishes Unlimited Discord in the "Beastiepedia: The Beastieball Wiki" thread in the Forums!

Module:AdjacentBeastie: Difference between revisions

From Beastiepedia: The Beastieball Wiki
No edit summary
No edit summary
Line 5: Line 5:
     local inputNumber = frame.args[1]
     local inputNumber = frame.args[1]
     local offset = tonumber(frame.args[2])
     local offset = tonumber(frame.args[2])
    local arrow = ""
    if offset == -1 then
        arrow = "←"
    else
        arrow = "→"
    end


     local tbl = "Beasties"
     local tbl = "Beasties"
Line 16: Line 10:
      
      
     local args = {
     local args = {
         where = string.format("SUBSTRING(Beasties.Number, 2, 5)='%02d'", tonumber(string.sub(inputNumber, 2)) + offset),
         where = string.format("Beasties.Number='%02d'", tonumber(string.sub(inputNumber, 2)) + offset),
     }
     }
      
      
     local results = cargo.query(tbl, fields, args)
     local results = cargo.query(tbl, fields, args)
     if #results > 0 then
     if #results > 0 then
         return string.format("[[%s|%s]]%s", results[1].Name, arrow, results[1].Number)
         if offset == -1 then
            return string.format("[[%s|←#%s]]", results[1].Name, results[1].Number)
        else
            return string.format("[[%s|#%s→]]", results[1].Name, results[1].Number)
        end
     else
     else
         return ""
         return ""

Revision as of 17:40, 21 November 2024

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

local p = {}
local cargo = mw.ext.cargo

function p.Main( frame )
    local inputNumber = frame.args[1]
    local offset = tonumber(frame.args[2])

    local tbl = "Beasties"
    local fields = "Number, Name"
    
    local args = {
        where = string.format("Beasties.Number='%02d'", tonumber(string.sub(inputNumber, 2)) + offset),
    }
    
    local results = cargo.query(tbl, fields, args)
    if #results > 0 then
        if offset == -1 then
            return string.format("[[%s|←#%s]]", results[1].Name, results[1].Number)
        else
            return string.format("[[%s|#%s→]]", results[1].Name, results[1].Number)
        end
    else
        return ""
    end
end

return p