Module:RecipeDetails/data

From IdleOn MMO Wiki
< Module:RecipeDetails
Revision as of 16:26, 12 April 2024 by Kiokurashi (talk | contribs) (Created page with "local data = {} -- Query smithing table for the recipe and retrieve the ingeredients local function _buildRecipeTable() local allRecipes = {} -- Query local args = { orderBy = 'AnvilCraft.Item' } local recipes = cargo.query('AnvilCraft', 'Item, Resource1, Quantity1, Resource2, Quantity2, Resource3, Quantity3, Resource4, Quantity4', args ) if #recipes == 0 then return {} end -- if no results, exit with an empty table. for r=1, #recipes do...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Find the generated data string in the Doccumenation page.


local data = {}
-- Query smithing table for the recipe and retrieve the ingeredients
local function _buildRecipeTable()
	local allRecipes = {}
	-- Query
    local args = {
        orderBy = 'AnvilCraft.Item'
    }
    local recipes = cargo.query('AnvilCraft', 'Item, Resource1, Quantity1, Resource2, Quantity2, Resource3, Quantity3, Resource4, Quantity4', args )
    if #recipes == 0 then return {} end -- if no results, exit with an empty table.
    for r=1, #recipes do
    	local itemRecipe = {}
    	local itemName = recipes[r].Item
    	itemRecipe.Item = itemName
    	local recipeArray = {}
	    for n=1, 4 do
	    	if recipes[r]['Resource'..n] == nil or recipes[r]['Resource'..n] == '' then break end -- If an empty cell is encountered, stop processing items.
	    	-- Append item and resource to array.
	    	recipeArray[#recipeArray+1] = recipes[r]['Resource'..n]
	    	recipeArray[#recipeArray+1] = recipes[r]['Quantity'..n]
	    end
	    itemRecipe.Recipe = recipeArray
	    -- Set item index to name of item.
	    allRecipes[itemName] = itemRecipe
	end
    -- Item = { Item = Item_Name, Recipe = {Item1, Amount1, Item2, Amount2, ...} }
	return allRecipes
end

local allRecipes = _buildRecipeTable()
return data