Difference between revisions of "Module:Item"

From Idlescape Wiki
Jump to navigation Jump to search
(test)
 
m
Line 12: Line 12:
 
end
 
end
 
 
for key, item in loaded_data_modules[module_name] do
+
for key, item in pairs(loaded_data_modules[module_name]) do
 
if name == item["name"] then
 
if name == item["name"] then
 
return item["id"]
 
return item["id"]

Revision as of 09:48, 11 September 2023


local p = {}

local data_module_names = {
	itemData = 'Module:Items/data'
}
local loaded_data_modules = {}

function p.loadItem (name, data_type) 
	local module_name = data_module_names[data_type]
	if loaded_data_modules[module_name] == nil then
		loaded_data_modules[module_name] = mw.loadData(module_name)
	end
	
	for key, item in pairs(loaded_data_modules[module_name]) do
		if name == item["name"] then
			return item["id"]
		end
	end
	
	return loaded_data_modules[module_name][item]
end

function p.addSeparator(num)
	return tostring(num):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
end

function p.item(frame)
	local args = frame:getParent().args
	return p._item(args)
end

function p._item(args)
	local name = args[1]
	local id = 0
			
	id = p.loadItem (name, 'itemData')
	id = tonumber(price)
	
	return id
end

return p