[set_variable]: do not iterate through all the elements of a random range

This commit is contained in:
Elvish_Hunter 2016-05-22 22:46:38 +02:00
parent 00525c340b
commit 8b82fb3248

View file

@ -1165,13 +1165,13 @@ function wml_actions.set_variable(cfg)
for i, item in ipairs(items) do
if type(item) == "table" then -- that's a range
for j = item[1], item[2] do
idx = idx - 1
if idx == 0 then
wesnoth.set_variable(name, j)
done = true
break
end
local elems = item[2] - item[1] + 1 -- amount of elements in the range, both ends included
if elems >= idx then
wesnoth.set_variable(name, item[1] + elems - idx)
done = true
break
else
idx = idx - elems
end
else -- that's a single element
idx = idx - 1