From 86701d53255b8d3c72dfd2fbf38bcf0ede7ba670 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Wed, 9 Jun 2021 18:51:55 +0200 Subject: [PATCH] sort keys numericly, i.e. p_2 before p_10 --- functions.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/functions.lua b/functions.lua index 104f559..90ef360 100644 --- a/functions.lua +++ b/functions.lua @@ -1950,13 +1950,26 @@ yl_speak_up.get_sorted_options = function(options, sort_by) end --- simple sort of keys of a table +-- simple sort of keys of a table numericly; +-- this is not efficient - but that doesn't matter: the lists are small and +-- it is only executed when configuring an NPC yl_speak_up.sort_keys = function(t) local keys = {} for k, v in pairs(t) do + -- add a prefix so that p_2 ends up before p_10 + if(string.len(k) == 3) then + k = "a"..k + end table.insert(keys, k) end table.sort(keys) + for i,k in ipairs(keys) do + -- avoid cutting the single a from a_1 (action 1) + if(k and string.sub(k, 1, 1) == "a" and string.sub(k, 1, 2) ~= "aa") then + -- remove the leading blank + keys[i] = string.sub(k, 2) + end + end return keys end