Module:Sandbox/User:The Gaffer/Modules/Infobox Recipe: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
The Gaffer (talk | contribs) No edit summary Tag: Manual revert |
The Gaffer (talk | contribs) 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 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
-- Calculate total cost and output cost |
-- Calculate total cost and output cost |
||
local totalCost = |
local totalCost = (rawmat1cost * (tonumber(args.rawmat1qty) or 1)) + |
||
(rawmat2cost * (tonumber(args.rawmat2qty) or 1)) + |
|||
(rawmat3cost * (tonumber(args.rawmat3qty) or 1)) |
|||
local output1cost = args.output1 and mw.smw.ask('[[:+]][[' .. args.output1 .. ']]|?Value|limit=1') or |
local output1cost = args.output1 and getCost(mw.smw.ask('[[:+]][[' .. args.output1 .. ']]|?Value|limit=1')) or 0 |
||
-- Calculate output cost total and profit |
-- Calculate output cost total and profit |
||
local output1costTotal = |
local output1costTotal = output1cost * (tonumber(args.output1qty) or 1) |
||
local profit = output1costTotal - totalCost |
local profit = output1costTotal - totalCost |
||