Add [set_variable]min|max= to calculate an extremum value
This commit is contained in:
parent
927fcbfb47
commit
4b2599864a
1 changed files with 18 additions and 0 deletions
|
@ -124,6 +124,24 @@ function wesnoth.wml_actions.set_variable(cfg, variables)
|
|||
local ivalue, fvalue = math.modf(tonumber(cfg.fpart) or 0)
|
||||
variables[name] = fvalue
|
||||
end
|
||||
|
||||
-- similarly, min and max operate on the list assigned to the variable
|
||||
-- and do not consider value already contained in the variable
|
||||
if cfg.min then
|
||||
local values = cfg.min:split()
|
||||
for i = 1, #values do
|
||||
values[i] = tonumber(values[i])
|
||||
end
|
||||
variables[name] = math.min(table.unpack(values))
|
||||
end
|
||||
|
||||
if cfg.max then
|
||||
local values = cfg.max:split()
|
||||
for i = 1, #values do
|
||||
values[i] = tonumber(values[i])
|
||||
end
|
||||
variables[name] = math.max(table.unpack(values))
|
||||
end
|
||||
|
||||
if cfg.string_length ~= nil then
|
||||
variables[name] = string.len(tostring(cfg.string_length))
|
||||
|
|
Loading…
Add table
Reference in a new issue