From 46d8bbaa8b98503d952dc6390398473fde966834 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 4 Oct 2020 13:10:28 -0400 Subject: [PATCH] Fix [set_variable][join] failing on boolean values --- .../utils/zombie-utils.cfg | 44 ++++--------------- data/lua/wml/set_variable.lua | 11 ++++- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/data/campaigns/Secrets_of_the_Ancients/utils/zombie-utils.cfg b/data/campaigns/Secrets_of_the_Ancients/utils/zombie-utils.cfg index d6d38b8c1b20..d696b841e500 100644 --- a/data/campaigns/Secrets_of_the_Ancients/utils/zombie-utils.cfg +++ b/data/campaigns/Secrets_of_the_Ancients/utils/zombie-utils.cfg @@ -120,47 +120,19 @@ # This macro saves the currently recruitable zombies into a string that can be used in a # [set_variables] statement later to restore the list. (LOAD_ZOMBIE_LIST does that.) #define SAVE_ZOMBIE_LIST VARIABLE - [foreach] - array=zombies - [do] - [if] - [variable] - name=this_item.allow_recruit - boolean_equals=yes - [/variable] - [then] - [set_variable] - name={VARIABLE} - value=${VARIABLE}| + "yes," - [/set_variable] - [/then] - [else] - [set_variable] - name={VARIABLE} - value=${VARIABLE}| + "no," - [/set_variable] - [/else] - [/if] - [/do] - [/foreach] - # Remove the trailing comma from the string. - [set_variable] - name={VARIABLE} - value="$(substring( '${VARIABLE}', 0, (length('${VARIABLE}')-1) ))" - [/set_variable] # This *should* work, but doesn't as of 1.14.5. It causes a lua error because of # concatenation of a boolean, presumably because the strings are all either # "yes" or "no". If that changes, this code can be uncommented, and the code # above removed. - # [set_variable] - # name=ardonna_zombies - # [join] - # variable=zombies - # key=allow_recruit - # separator="," - # [/join] - # [/set_variable] + [set_variable] + name=ardonna_zombies + [join] + variable=zombies + key=allow_recruit + separator="," + [/join] + [/set_variable] #enddef #define LOAD_ZOMBIE_LIST VARIABLE diff --git a/data/lua/wml/set_variable.lua b/data/lua/wml/set_variable.lua index 323b06b04c0f..19504c727c27 100644 --- a/data/lua/wml/set_variable.lua +++ b/data/lua/wml/set_variable.lua @@ -148,7 +148,16 @@ function wesnoth.wml_actions.set_variable(cfg, variables) if #string_to_join > 0 then string_to_join = string_to_join .. separator end - string_to_join = string_to_join .. element[key_name] + local elem = element[key_name] + if type(elem) == 'boolean' then + -- Use yes/no instead of true/false for booleans + elem = elem and 'yes' or 'no' + elseif getmetatable(elem) ~= 'translatable string' then + -- Not entirely sure if this branch is necessary, since it probably only triggers for numbers + -- It certainly can't hurt, though. + elem = tostring(elem) + end + string_to_join = string_to_join .. elem end end