Module:Item in other games

local p = {} local cargo = mw.ext.cargo local convertCase = require('Module:SentenceCase').firstToUpper

function tableEmpty(s) return next(s) == nil end

function isEmpty(s) return s == nil or s == '' end

function p.main( frame ) -- Declare variables local print = '' local tables local fields local args local results -- Determine the cargo table to which the module will pull from. if frame.args['game'] == "First gen" then tables = 'pg_identifier' fields = "pg_identifier.identifier=identifier" args = { where = "pg_identifier._pageName = \"" .. frame.args['1']:gsub("\'","\\'") .. "\"", limit = 1, groupBy = 'pg_identifier._pageName', default = '', }	   results = cargo.query( tables, fields, args ) elseif frame.args['game'] == "Wild World" then tables = 'ww_identifier' fields = "ww_identifier.identifier=identifier" args = { where = "ww_identifier._pageName = \"" .. frame.args['1']:gsub("\'","\\'") .. "\"", limit = 1, groupBy = 'ww_identifier._pageName', default = '', }	   results = cargo.query( tables, fields, args ) elseif frame.args['game'] == "City Folk" then print = "Not implemented yet" results = {} elseif frame.args['game'] == "New Leaf" then tables = 'nl_identifier' fields = "nl_identifier.identifier=identifier" args = { where = "nl_identifier._pageName = \"" .. frame.args['1']:gsub("\'","\\'") .. "\"", limit = 1, groupBy = 'nl_identifier._pageName', default = '', }	   results = cargo.query( tables, fields, args ) elseif frame.args['game'] == "New Horizons" then tables = 'nh_identifier' fields = "nh_identifier.identifier=identifier" args = { where = "nh_identifier._pageName = \"" .. frame.args['1']:gsub("\'","\\'") .. "\"", limit = 1, groupBy = 'nh_identifier._pageName', default = '', }	   results = cargo.query( tables, fields, args ) else print = "Game not specified." results = {} end -- Comb through every identifer table and return a value if item found. if not tableEmpty(results) then local data = {} local offset = 0 -- Check first gen identifer cargo table local firstGen = cargo.query( 'pg_identifier', "pg_identifier._pageName=pageName,pg_identifier.en_name=name", {where = "pg_identifier.identifier = \"" .. results[1].identifier .. "\"", limit = 100, groupBy = 'pg_identifier._pageName', default = ''} ) if not tableEmpty(firstGen) and frame.args['game'] ~= "First gen" then for r = 1, #firstGen do data[r] = "" .. convertCase (firstGen[r].name) .. " (" .. firstGen[r].pageName:gsub("Item:.*%((.-)%)","%1") .. ")" offset = offset + r	   	end end -- Check Wild World identifier cargo table local wildWorld = cargo.query( 'ww_identifier', "ww_identifier._pageName=pageName,ww_identifier.en_name=name", {where = "ww_identifier.identifier = \"" .. results[1].identifier .. "\"", limit = 100, groupBy = 'ww_identifier._pageName', default = ''} ) if not tableEmpty(wildWorld) and frame.args['game'] ~= "Wild World" then for r = 1, #wildWorld do data[r+offset] = "" .. convertCase (wildWorld[r].name) .. " (Wild World)" offset = offset + r	   	end end -- Check New Leaf identifier cargo table local newLeaf = cargo.query( 'nl_identifier', "nl_identifier._pageName=pageName,nl_identifier.en_name=name", {where = "nl_identifier.identifier = \"" .. results[1].identifier .. "\"", limit = 100, groupBy = 'nl_identifier._pageName', default = ''} ) if not tableEmpty(newLeaf) and frame.args['game'] ~= "New Leaf" then for r = 1, #newLeaf do data[r+offset] = "" .. convertCase (newLeaf[r].name) .. " (New Leaf)" offset = offset + r	   	end end -- Check New Horizons identifier cargo table local newHorizons = cargo.query( 'nh_identifier', "nh_identifier._pageName=pageName,nh_identifier.en_name=name", {where = "nh_identifier.identifier = \"" .. results[1].identifier .. "\"", limit = 100, groupBy = 'nh_identifier._pageName', default = ''} ) if not tableEmpty(newHorizons) and frame.args['game'] ~= "New Horizons" then for r = 1, #newHorizons do data[r+offset] = "" .. convertCase (newHorizons[r].name) .. " (New Horizons)" offset = offset + r	   	end end if not tableEmpty(data) then if not isEmpty(frame.args['hide-section-title']) then print = print else print = print .. "== In other games ==\n" end print = print .. "" for r = 1, #data do print = print .. data[r] end print = print .. "" if not isEmpty(frame.args['hide-section-title']) then print = print else print = print .. "\n" end end end return print end

return p