Module:Shop: Difference between revisions

130 bytes removed ,  27 December 2022
Use printError function
m (Re-order columns for cooking fire output)
(Use printError function)
Line 75: Line 75:


if Shared.tableIsEmpty(purchaseList) then
if Shared.tableIsEmpty(purchaseList) then
return "ERROR: Couldn't find purchase with name '" .. purchaseName .. "'[[Category:Pages with script errors]]"
return Shared.printError("Couldn't find purchase with name '" .. purchaseName .. "'")
else
else
local resultPart = {}
local resultPart = {}
Line 283: Line 283:
             table.insert(reqArray, reqText)
             table.insert(reqArray, reqText)
         else
         else
             table.insert(reqArray, 'ERROR: Unknown requirement: ' .. (req.type or 'nil') .. '[[Category:Pages with script errors]]')
             table.insert(reqArray, Shared.printError('Unknown requirement: ' .. (req.type or 'nil')))
         end
         end
     end
     end
Line 364: Line 364:


if purchase == nil then
if purchase == nil then
return "ERROR: Couldn't find purchase with name '" .. purchaseName .. "'[[Category:Pages with script errors]]"
return Shared.printError("Couldn't find purchase with name '" .. purchaseName .. "'")
else
else
return p._getPurchaseContents(purchase, asList)
return p._getPurchaseContents(purchase, asList)
Line 405: Line 405:
if purchase == nil then
if purchase == nil then
return "ERROR: Couldn't find purchase with name '" .. purchaseName .. "'[[Category:Pages with script errors]]"
return Shared.printError("Couldn't find purchase with name '" .. purchaseName .. "'")
else
else
return p._getPurchaseBuyLimit(purchase, asList)
return p._getPurchaseBuyLimit(purchase, asList)
Line 437: Line 437:


if purchase == nil then
if purchase == nil then
return "ERROR: Couldn't find purchase with name '" .. tostring(purchaseName) .. "'[[Category:Pages with script errors]]"
return Shared.printError("Couldn't find purchase with name '" .. tostring(purchaseName) .. "'")
else
else
args[1] = purchase
args[1] = purchase
Line 606: Line 606:
     local shopCat = GameData.getEntityByName('shopCategories', cat)
     local shopCat = GameData.getEntityByName('shopCategories', cat)
if shopCat == nil then
if shopCat == nil then
return 'ERROR: Invalid category '..cat..'[[Category:Pages with script errors]]'
return Shared.printError('Invalid category ' .. cat)
else
else
         local catPurchases = p.getPurchases(function(purch) return purch.category == shopCat.id end)
         local catPurchases = p.getPurchases(function(purch) return purch.category == shopCat.id end)
Line 683: Line 683:
local item = Items.getItem(itemName)
local item = Items.getItem(itemName)
if item == nil then
if item == nil then
return "ERROR: No item named "..itemName.." exists in the data module"
return Shared.printError('No item named ' .. itemName .. ' exists in the data module')
end
end


Line 958: Line 958:
local validCategories = {'Cooking Fire', 'Furnace', 'Pot'}
local validCategories = {'Cooking Fire', 'Furnace', 'Pot'}
if category == nil or not Shared.contains({'Cooking Fire', 'Furnace', 'Pot'}, category) then
if category == nil or not Shared.contains({'Cooking Fire', 'Furnace', 'Pot'}, category) then
return 'ERROR: Invalid category specified. Must be one of the following: ' .. mw.text.listToText(validCategories, ', ', ' or ')
return Shared.printError('Invalid category specified. Must be one of the following: ' .. mw.text.listToText(validCategories, ', ', ' or '))
end
end