Module:Sandbox: Difference between revisions

From the Super Mario Wiki, the Mario encyclopedia
Jump to navigationJump to search
mNo edit summary
mNo edit summary
Line 38: Line 38:
local imageBase = args.item or item
local imageBase = args.item or item
imageBase = imageBase:gsub("é", "e")
if game == "PMTOK" and imageBase == "Spring of Rainbows - VIP" then
imageBase = imageBase:gsub("×", "x")
imageBase = "Spring of Rainbows VIP"
imageBase = imageBase:gsub("[.,'?!]", "")
else
imageBase = imageBase:gsub('"', "")
imageBase = string.gsub(imageBase, "é", "e")
imageBase = string.gsub(imageBase, "×", "x")
imageBase = string.gsub(imageBase, "[.,'?!]", "")
imageBase = string.gsub(imageBase, '"', "")
if game == "PM" then
imageBase = string.gsub(imageBase, " ", "")
end
end
return string.format("game=%s<br>item=%s<br>link=%s<br>text=%s<br>image-size=%s<br>image-prefix=%s<br>image-suffix=%s<br>image-base=%s", game, item, link, text, imageSize or "nil", imagePrefix, imageSuffix, imageBase)
return string.format("game=%s<br>item=%s<br>link=%s<br>text=%s<br>image-size=%s<br>image-prefix=%s<br>image-suffix=%s<br>image-base=%s", game, item, link, text, imageSize or "nil", imagePrefix, imageSuffix, imageBase)

Revision as of 11:15, November 17, 2020

The sandbox (Module:Sandbox) is a module namespace page designed for testing and experimenting with Lua syntax. Feel free to try your skills at programming here: Click on edit, make your changes, then click "Save changes" when you are finished. Code added here will not stay permanently. Feel free to revert the page to its hello world function when you are done using it. This is not a page to chat.

If you need further help with modules, see the Lua reference manual.


local p = {}

function p.hello( frame )
    return "'''Hello, world!'''"
end

function p.pmitem(frame)
	local args = frame.args
	local game = args.game or "PM"
	local item = args[2] or args[1]
	local link = args.link or args[1]
	local text = args.text or item
	
	local imageSize = args.size
	if imageSize == nil then
		if game == "TTYD" then
			imageSize = "25x25px"
		elseif game ~= "PM" and game ~= "SPM" then
			imageSize = "50x50px"
		end
	end
	
	local imagePrefix = ""
	if game == "PM" then
		imagePrefix = "PaperMario Items "
	elseif game == "PMCS" then
		imagePrefix = "PMCS Item "
	end
	
	local imageSuffix = ""
	if game == "TTYD" or game == "SPM" then
		imageSuffix = " " .. game
	elseif game == "PMSS" then
		imageSuffix = " Sticker PMSS"
	elseif game == "PMTOK" then
		imageSuffix = " PMTOK icon"
	end
	
	local imageBase = args.item or item
	if game == "PMTOK" and imageBase == "Spring of Rainbows - VIP" then
		imageBase = "Spring of Rainbows VIP"
	else
		imageBase = string.gsub(imageBase, "é", "e")
		imageBase = string.gsub(imageBase, "×", "x")
		imageBase = string.gsub(imageBase, "[.,'?!]", "")
		imageBase = string.gsub(imageBase, '"', "")
		if game == "PM" then
			imageBase = string.gsub(imageBase, " ", "")
		end
	end
	
	return string.format("game=%s<br>item=%s<br>link=%s<br>text=%s<br>image-size=%s<br>image-prefix=%s<br>image-suffix=%s<br>image-base=%s", game, item, link, text, imageSize or "nil", imagePrefix, imageSuffix, imageBase)
end

return p