Skip to content

Commit

Permalink
Support [set_variable]round=trunc
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Apr 12, 2018
1 parent 3efa619 commit d06759a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions data/lua/wml/set_variable.lua
Expand Up @@ -70,6 +70,11 @@ function wesnoth.wml_actions.set_variable(cfg)
wesnoth.set_variable(name, math.ceil(var))
elseif round_val == "floor" then
wesnoth.set_variable(name, math.floor(var))
elseif round_val == "trunc" then
-- Storing to a variable first because modf returns two values,
-- and I'm not sure if set_variable will complain about the extra parameter
local new_val = math.modf(var)
wesnoth.set_variable(name, new_val)
else
local decimals = math.modf(tonumber(round_val) or 0)
local value = var * (10 ^ decimals)
Expand Down

0 comments on commit d06759a

Please sign in to comment.