From c8abb8d5d99cc93b590fd6ae934dd8b2d9a1ba2d Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Fri, 2 Feb 2018 15:40:44 +1100 Subject: [PATCH] Add formula= option to [set_variable] (change by @celticminstrel) [ci skip] --- changelog | 2 ++ data/lua/wml/set_variable.lua | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/changelog b/changelog index aa94dfa1de62..25b1db1f6195 100644 --- a/changelog +++ b/changelog @@ -66,6 +66,8 @@ Version 1.13.10+dev: improvement over the uncut ruby of fire (14x4) in TRoW. * Added [lua] as a conditional tag. * Lua errors now cause as a condition to fail instead of pass. + * New formula= key in [set_variable] allows evaluating a WFL formula with + the variable, which may be either a scalar or a container. * Miscellaneous and bug fixes: * Fixed crash after canceling add-on download (bug #2203) * Fixed ingame help showing units you haven't encountered (bug #2135) diff --git a/data/lua/wml/set_variable.lua b/data/lua/wml/set_variable.lua index f20dbdbccbc3..d63bd0599456 100644 --- a/data/lua/wml/set_variable.lua +++ b/data/lua/wml/set_variable.lua @@ -98,6 +98,11 @@ function wesnoth.wml_actions.set_variable(cfg) wesnoth.set_variable(name, helper.rand(tostring(cfg.rand))) end + if cfg.formula then + local fcn = wesnoth.compile_formula(cfg.formula) + wesnoth.set_variable(name, fcn(wesnoth.get_variable(name))) + end + local join_child = helper.get_child(cfg, "join") if join_child then local array_name = join_child.variable or helper.wml_error "missing variable= attribute in [join]"