Module:HeroData: Difference between revisions

Jump to navigation Jump to search
Sur (talk | contribs)
m statboxattrs > statinfoboxorder
Sur (talk | contribs)
m get_hero_var optional parameter to round to N sig figs
Line 28: Line 28:




--{{#invoke:HeroData|get_hero_var|HERO_NAME|STAT_NAME}}--
--{{#invoke:HeroData|get_hero_var|HERO_NAME|STAT_NAME|sig_figs}}--
--sig_figs optional for rounding floats
p.get_hero_var = function(frame)
p.get_hero_var = function(frame)
local hero_name = frame.args[1]
local hero_name = frame.args[1]
local hero_stat_key = frame.args[2]
local hero_stat_key = frame.args[2]
local sig_figs = frame.args[3]
local hero = p.get_json_item(hero_name)
local hero = p.get_json_item(hero_name)
Line 38: Line 40:
local var_value = hero[hero_stat_key]
local var_value = hero[hero_stat_key]
if(var_value == nil) then return 0 end
if(var_value == nil) then return 0 end
--round
if (sig_figs ~= nil) then
var_value = util_module.round_to_sig_fig(var_value, sig_figs)
if (var_value == nil) then return "get_hero_var() error with rounding" end
end


return var_value
return var_value