Module:Sandbox/User:The Gaffer/Modules/Infobox Recipe: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(Created page with "-- Lua module to replicate the functionality of the Infobox Recipe template local p = {} function p._main(frame) local args = frame.args local mw = require('mw') -- Define raw material costs based on Semantic MediaWiki queries local rawmat1cost = args.rawmat1 and mw.smw.ask('+Sold item::' .. args.rawmat1 .. '|?Shop buy price|sort=Shop buy price|order=asc|limit=1') or "0" local rawmat2cost = args.rawmat2 and mw.smw.ask('+[[Sold item::'...")
 
No edit summary
Line 7: Line 7:


-- Define raw material costs based on Semantic MediaWiki queries
-- Define raw material costs based on Semantic MediaWiki queries
local function getCost(queryResult)
if type(queryResult) == "table" and queryResult[1] then
return tonumber(queryResult[1]) or 0
end
return 0
end

local rawmat1cost = args.rawmat1 and mw.smw.ask('[[:+]][[Sold item::' .. args.rawmat1 .. ']]|?Shop buy price|sort=Shop buy price|order=asc|limit=1') or "0"
local rawmat1cost = args.rawmat1 and mw.smw.ask('[[:+]][[Sold item::' .. args.rawmat1 .. ']]|?Shop buy price|sort=Shop buy price|order=asc|limit=1') or "0"
local rawmat2cost = args.rawmat2 and mw.smw.ask('[[:+]][[Sold item::' .. args.rawmat2 .. ']]|?Shop buy price|sort=Shop buy price|order=asc|limit=1') or "0"
local rawmat2cost = args.rawmat2 and mw.smw.ask('[[:+]][[Sold item::' .. args.rawmat2 .. ']]|?Shop buy price|sort=Shop buy price|order=asc|limit=1') or "0"