Module:WeightToPercent: Difference between revisions

From eMushpedia
Jump to navigation Jump to search
imported>Septembre
debug 5: seems like it's not working if you don't use magic word parentOnly
imported>Septembre
on arrête l'utilisation du module Arguments
Line 1: Line 1:
local getArgs = require('Module:Arguments').getArgs
local p = {}
local p = {}


function p.main(frame)
function p.convert(frame)
local args = getArgs(frame, {trim = true, removeBlanks = true, parentOnly = true})
local weight = frame.args['weight']
return p.convert(args)
local totalweight = frame.args['total']
end
function p.convert(args)
local weight = args[1]
local totalweight = args[2]
if weight == nil then return "ERROR: weight input (1rst arg) is nil"
if weight == nil then return "ERROR: weight input (1rst arg) is nil"
elseif totalweight == nil then return "ERROR: totalweight (2nd arg) input is nil"
elseif totalweight == nil then return "ERROR: totalweight (2nd arg) input is nil"
elseif weight == 0 then return 0
elseif weight == 0 then return 0
     else return 100 * totalweight / weight end
     end
    return 100 * totalweight / weight
end
end
   
   
return p
return p

Revision as of 14:42, 19 November 2025

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

local p = {}

function p.convert(frame)
	local weight = frame.args['weight']
	local totalweight = frame.args['total']
	
	if weight == nil then return "ERROR: weight input (1rst arg) is nil"
	elseif totalweight == nil then return "ERROR: totalweight (2nd arg) input is nil"
	elseif weight == 0 then return 0
    end
    return 100 * totalweight / weight
end
 
return p