From b94ccf9020994ce4d8d2b844f20bfec80647451d Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 11 Mar 2018 13:31:47 -0400 Subject: [PATCH] Rewrite helper.modify_unit to not use a WML variable --- data/lua/helper.lua | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/data/lua/helper.lua b/data/lua/helper.lua index b23ce2c0fb3..f3a8b22b5c5 100644 --- a/data/lua/helper.lua +++ b/data/lua/helper.lua @@ -39,22 +39,15 @@ end --! @param vars key/value pairs that need changing. --! @note Usable only during WML actions. function helper.modify_unit(filter, vars) - wml_actions.store_unit({ - [1] = { "filter", filter }, - variable = "LUA_modify_unit", - kill = true - }) - for i = 0, wml.variables["LUA_modify_unit.length"] - 1 do - local u = string.format("LUA_modify_unit[%d]", i) + local units = wesnoth.get_units(filter) + for u in pairs(units) do for k, v in pairs(vars) do - wml.variables[u .. '.' .. k] = v + -- Minor TODO: What if you want to change values of subtags? + -- Previously would've been possible with eg {['variables.some_var'] = 'some_value'} + -- With this implementation, it's not possible. + u[k] = v end - wml_actions.unstore_unit({ - variable = u, - find_vacant = false - }) end - wml.variables["LUA_modify_unit"] = nil end --! Fakes the move of a unit satisfying the given @a filter to position @a x, @a y.