Sanity test in [for] for sgn(step) ~= sgn(last-first)

This commit is contained in:
Celtic Minstrel 2015-10-01 14:29:47 -04:00
parent 281f952a08
commit 13033270ae

View file

@ -361,6 +361,12 @@ wesnoth.wml_actions["for"] = function(cfg)
last = cfg["end"] or first
step = cfg.step or ((last - first) / math.abs(last - first))
end
if ((last - first) / math.abs(last - first)) ~= (step / math.abs(step)) then
-- Sanity check: If they specify something like start,end,step=1,4,-1
-- then we interpret it as start,end,step=4,1,-1
-- (The step takes precedence since it's optional.)
last, first = first, last
end
local i_var = cfg.variable or "i"
local save_i = utils.start_var_scope(i_var)
wesnoth.set_variable(i_var, first)