Skip to content

Commit

Permalink
Fix [set_variable][join] failing on boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Oct 4, 2020
1 parent 6016b81 commit 46d8bba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 37 deletions.
44 changes: 8 additions & 36 deletions data/campaigns/Secrets_of_the_Ancients/utils/zombie-utils.cfg
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion data/lua/wml/set_variable.lua
Expand Up @@ -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

Expand Down

0 comments on commit 46d8bba

Please sign in to comment.