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 -- 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 = 1, groupBy = 'pg_identifier._pageName', default = ''} ) if not tableEmpty(firstGen) and not frame.args['game'] == "First gen" then for r = 1, #firstGen do print = print .. "" .. convertCase (firstGen[r].name) .. " (" .. firstGen[r].pageName:gsub(".*%(.-%)","%1") .. ")" 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 = 1, groupBy = 'ww_identifier._pageName', default = ''} ) if not tableEmpty(wildWorld) and not frame.args['game'] == "Wild World" then for r = 1, #wildWorld do print = print .. "" .. convertCase (wildWorld[r].name) .. " (Wild World)" 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 = 1, groupBy = 'nl_identifier._pageName', default = ''} ) if not tableEmpty(newLeaf) and not frame.args['game'] == "New Leaf" then for r = 1, #newLeaf do print = print .. "" .. convertCase (newLeaf[r].name) .. " (New Leaf)" 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 = 1, groupBy = 'nh_identifier._pageName', default = ''} ) if not tableEmpty(newHorizons) and not frame.args['game'] == "New Horizons" then for r = 1, #newHorizons do print = print .. "" .. convertCase (newHorizons[r].name) .. " (New Horizons)" end end end return print end

return p