Module:Recipe: Difference between revisions

From Subnautica Wiki
No edit summary
(adding check for items crafted as part of other recipes)
Line 8: Line 8:
if args[1] then
if args[1] then
if data[args[1]] then
if data[args[1]] then
return data[args[1]].name
if data[args[1]].original then
error ("'" .. args[1] .. "' is not crafted standalone; use '" .. data[args[1]].original .. "' instead")
else
return data[args[1]].name
end
else
else
error ("'" .. args[1] .. "' recipe does not exist")
error ("'" .. args[1] .. "' recipe does not exist")

Revision as of 22:19, 8 June 2022

This module standardizes the display of crafting recipes and makes it easy to display a specified item's recipe or all recipes that use a specified ingredient. See Template:RecipeNew for more information. Thanks to BryghtShadow for helping out with the loops!


local p = {}
local data = mw.loadData('Module:Recipe/data')
local getArgs = require('Dev:Arguments').getArgs

function p.main(frame)
	local args = getArgs(frame)
	
	if args[1] then
		if data[args[1]] then
			if data[args[1]].original then
				error ("'" .. args[1] .. "' is not crafted standalone; use '" .. data[args[1]].original .. "' instead")
			else
				return data[args[1]].name
			end
		else
			error ("'" .. args[1] .. "' recipe does not exist")
		end
	end
end

return p