From a0f2f5b340670495268cd80c4ac39c8bcd3d8cda Mon Sep 17 00:00:00 2001 From: Sokomine Date: Mon, 5 Sep 2022 07:27:29 +0200 Subject: [PATCH] show correct item in trade limit list when returning from editing an entry --- fs_trade_limit.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs_trade_limit.lua b/fs_trade_limit.lua index 4207ef4..4dff53c 100644 --- a/fs_trade_limit.lua +++ b/fs_trade_limit.lua @@ -176,19 +176,14 @@ yl_speak_up.get_fs_trade_limit = function(player, selected) -- the table event selection returns a row index - we need to translate that to our table local item_list = {} - local descr_list = {} for k,v in pairs( items ) do table.insert(item_list, k) end -- avoid total chaos by sorting this list table.sort(item_list) local row = 2 - local selected_row = 1 for i, k in ipairs( item_list ) do local v = items[k] - if(selected and k == selected) then - selected_row = #item_list + 1 - end local c1 = '#FF0000' if( v[1] > 0 ) then c1 = '#BBBBBB' @@ -225,6 +220,10 @@ yl_speak_up.get_fs_trade_limit = function(player, selected) yl_speak_up.speak_to[pname].trade_limit_items = items yl_speak_up.speak_to[pname].trade_limit_item_list = item_list - table.insert(formspec, ";"..selected_row) + local selected_row = 1 + if(selected and selected ~= "") then + selected_row = math.max(1, table.indexof(item_list, selected) + 1) + end + table.insert(formspec, ";"..selected_row.."]") return table.concat(formspec, '') end