Module:SlabStuff: Difference between revisions

From IdleOn MMO Wiki
(Created page with "local slab = {} function slab.slabOrderList(frame) local bigList = frame.args.OrderList local tableList = explode(bigList, ',') local ret = '' for i = 1, #tableList do mw.ext.VariablesLua.vardefine('Slaborder', i - 1) ret = ret .. '{{SlabOrder/store|Item=' .. tableList[i] .. '|Number=' .. i-1 .. '}}' end return ret end function slab.SlabNumGrab(frame) local item = frame.args.Item local tables = 'SlabOrder' local fields = 'Number' local args = {...")
 
mNo edit summary
Tag: Manual revert
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
local slab = {}
local slab = {}
local cargo = mw.ext.cargo
local function explode(list, delimiter)
    if delimiter == nil then
delimiter = "%s"
end
t = {}
for str in string.gmatch(list, "([^" .. delimiter .. "]+)") do
table.insert(t, str)
end
return t
end


function slab.slabOrderList(frame)  
function slab.slabOrderList(frame)  
Line 6: Line 18:
local ret = ''
local ret = ''
for i = 1, #tableList do
for i = 1, #tableList do
mw.ext.VariablesLua.vardefine('Slaborder', i - 1)
frame:expandTemplate{ title = 'SlabOrder/store', args = { Item = tableList[i], Number = i } }
ret = ret .. '{{SlabOrder/store|Item=' .. tableList[i] .. '|Number=' .. i-1 .. '}}'
end
end

Latest revision as of 09:52, 7 April 2023

Documentation for this module may be created at Module:SlabStuff/doc

local slab = {}
local cargo = mw.ext.cargo

local function explode(list, delimiter)
    if delimiter == nil then
		delimiter = "%s"
	end
	t = {}
	for str in string.gmatch(list, "([^" .. delimiter .. "]+)") do
		table.insert(t, str)
	end
	return t
end

function slab.slabOrderList(frame) 
	local bigList = frame.args.OrderList
	local tableList = explode(bigList, ',')
	local ret = ''
	for i = 1, #tableList do
		frame:expandTemplate{ title = 'SlabOrder/store', args = { Item = tableList[i], Number = i } }
	end
	
	return ret
end

function slab.SlabNumGrab(frame)
	local item = frame.args.Item
	local tables = 'SlabOrder'
    local fields = 'Number'
    local args = {
        where = 'SlabOrder.Item="'.. item ..'"',
		orderBy = 'SlabOrder.Number',
		default = ''
    }
    local results = cargo.query( tables, fields, args )
    if #results == 0 then return '' end -- if no results, return original string and continue.
    mw.ext.VariablesLua.vardefine('SlabNum', results[1].Number)
    return ''
end

return slab